Использование этого. Я сделал то, что, когда кнопка была нажата, она сохраняет весь макет таким же способом, что и захват снимков экрана.
linearLayout = (LinearLayout) findViewById(R.id.screenshots); //say for eg: this is the main layout id wich holds everything(images etc)
//use a button to call this method.
private void saveLayout() {
// View v1 = getWindow().getDecorView().getRootView();
View v1 = linearLayout.getRootView();
v1.setDrawingCacheEnabled(true);
myBitmap = v1.getDrawingCache();
if (myBitmap != null) {
Toast.makeText(MainScreen.this, "Bitmap not null",
Toast.LENGTH_SHORT).show();
saveBitmap(myBitmap);
} else {
Toast.makeText(MainScreen.this, "Bitmap null",Toast.LENGTH_SHORT).show();
}
}
private void saveBitmap(Bitmap bitmap) {
try {
File mFolder = new File(getFilesDir() + "/nmc"); //give a name for the folder
File imagePath = new File(mFolder + "screenshot.png");
if (!mFolder.exists()) {
mFolder.mkdir();
}
if (!imagePath.exists()) {
imagePath.createNewFile();
}
FileOutputStream fos=null;
fos = new FileOutputStream(imagePath);
// bitmap.compress(CompressFormat.PNG, 100, fos);
bitmap.compress(Bitmap.CompressFormat.PNG, 60, fos);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] byteArray = byteArrayOutputStream.toByteArray();
String encodedByte = Base64.encodeToString(byteArray,Base64.DEFAULT);
Log.e("encodeByte", encodedByte);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(), bitmap,"Screen", "screen");
} catch (FileNotFoundException e) {
Log.e("no file", e.getMessage(), e);
} catch (IOException e) {
Log.e("io", e.getMessage(), e);
}
}
Я думаю, вы можете попробовать рисовать представление, которое вам нужно для растрового изображения, а затем сохранить его. –
Просто Google это .. Есть тонны уроков, чтобы снять снимок экрана –
Просто помните, что вы можете получить только скриншот из своего приложения. Нет нижней панели или строки состояния, и, как я помню, нет открытых меню. –