Sceneform-android-sdk: SceneView - Screenshot

Created on 10 Jul 2018  路  3Comments  路  Source: google-ar/sceneform-android-sdk

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.

Most helpful comment

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)

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rohitagarwal3011 picture rohitagarwal3011  路  4Comments

PaulTVungle picture PaulTVungle  路  3Comments

chiaolinghong3d picture chiaolinghong3d  路  3Comments

KamikX picture KamikX  路  4Comments

dementia2029 picture dementia2029  路  3Comments