sceneform-android-sdk icon indicating copy to clipboard operation
sceneform-android-sdk copied to clipboard

SceneView - Screenshot

Open peronecode opened this issue 8 years ago • 3 comments

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.

peronecode avatar Jul 10 '18 20:07 peronecode

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 avatar Jul 10 '18 23:07 romainguy

@romainguy It works fine for me now. Thanks for reply. Regards.

peronecode avatar Jul 13 '18 18:07 peronecode

@peronecode plz give the source code of working screenshot ASAP. i need that plz

AmzMirza avatar Jun 30 '19 07:06 AmzMirza