В этой функции вам просто нужно передать представление, которое даст вам растровое изображение, которое вы можете сохранить или показать на изображении
public void takeScreenshot(View screenshotView) {
try {
View view = null;
Bitmap b = null;
if (screenshotView instanceof TextureView) {
b = ((TextureView) screenshotView).getBitmap();
} else {
view = screenshotView;
}
if (view != null) {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
b = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
}
if (imageViewParentLayout != null) {
if (imageView != null) {
imageView.setVisibility(View.VISIBLE);
imageView.setImageBitmap(b);
}
}
String path = saveToAlbum(b);
Notify.INSTANCE.Toast("Image Saved :" + path);
scanfiles(path);
} catch (Exception e) {
e.printStackTrace();
Notify.INSTANCE.Toast("Something Went Wrong");
}finally {
hideImageView();
}
}
private void scanfiles(String path) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
File outputFile = new File(path);
final Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
final Uri contentUri = Uri.fromFile(outputFile);
scanIntent.setData(contentUri);
AppController.getAppContext().sendBroadcast(scanIntent);
} else {
final Intent intent = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()));
AppController.getAppContext().sendBroadcast(intent);
}
} catch (Exception e) {
e.printStackTrace();
File file=new File(path);
MediaScannerConnection.scanFile(AppController.getAppContext(), new String[]{
file.getAbsolutePath()},
null, (path1, uri) -> {
});
}
}