Hello everyone.
I have an issue for take screenshots of the model with SceneView, without using ARCore and ArFragment layout. Therefore I load my SFB file and show it correctly, but, when I'm trying to take a screenshot, with the function above, I'm only get a black image with correct dimensions as my device screen.
Take screenshot function:
private void takeScreenshot() {
try {
String mPath = Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DCIM + "/Screenshots/output_screenshot.jpg";
View view = getWindow().getDecorView().getRootView();
view.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
I already trying to use PixelCopy passing my Window, instead ArFragment (because I don't have it), to the function, and get the same result as my custom function.
Am I doing something wrong or there is another way to take this shots?
Thanks for your attention.
Regards, Perone.
You cannot take a screenshot of a SurfaceView using View.getDrawingCache(). It only works for content rendered by a regular View with a Canvas.
For PixelCopy to work you simply need to pass the SurfaceView (aka the SceneView). No need to pass the Window: https://developer.android.com/reference/android/view/PixelCopy.html#request(android.view.SurfaceView,%20android.graphics.Bitmap,%20android.view.PixelCopy.OnPixelCopyFinishedListener,%20android.os.Handler)
@romainguy It works fine for me now. Thanks for reply. Regards.
@peronecode plz give the source code of working screenshot ASAP. i need that plz
Most helpful comment
You cannot take a screenshot of a
SurfaceViewusingView.getDrawingCache(). It only works for content rendered by a regularViewwith aCanvas.For
PixelCopyto work you simply need to pass theSurfaceView(aka theSceneView). No need to pass theWindow: https://developer.android.com/reference/android/view/PixelCopy.html#request(android.view.SurfaceView,%20android.graphics.Bitmap,%20android.view.PixelCopy.OnPixelCopyFinishedListener,%20android.os.Handler)