How to take a screenshot of Android's Surface View?












9















I want to programatically take screen shot of my game, just as you'd get in Eclipse DDMS.



Screenshot taken through the solution proposed here: How to programmatically take a screenshot in Android? and in most other SO questions only have View elements visible, but not the SurfaceView.



SCREENSHOTS_LOCATIONS = Environment.getExternalStorageDirectory().toString() + "/screenshots/";
// Get root view
View view = activity.getWindow().getDecorView().getRootView();
// Create the bitmap to use to draw the screenshot
final Bitmap bitmap = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);

// Get current theme to know which background to use
final Theme theme = activity.getTheme();
final TypedArray ta = theme
.obtainStyledAttributes(new int { android.R.attr.windowBackground });
final int res = ta.getResourceId(0, 0);
final Drawable background = activity.getResources().getDrawable(res);

// Draw background
background.draw(canvas);

// Draw views
view.draw(canvas);

// Save the screenshot to the file system
FileOutputStream fos = null;
try {
final File sddir = new File(SCREENSHOTS_LOCATIONS);
if (!sddir.exists()) {
sddir.mkdirs();
}
fos = new FileOutputStream(SCREENSHOTS_LOCATIONS
+ System.currentTimeMillis() + ".jpg");
if (fos != null) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)) {
Log.d("ScreenShot", "Compress/Write failed");
}
fos.flush();
fos.close();
}

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


Any help in this regard would be highly appreciated. Thanks.










share|improve this question

























  • so you want to capture the view that are not visible or are beneath some other view?

    – Nimish Choudhary
    Jan 31 '13 at 7:00











  • Possible duplicate of Android Take Screenshot of Surface View Shows Black Screen

    – Anjani Mittal
    Nov 22 '18 at 11:26
















9















I want to programatically take screen shot of my game, just as you'd get in Eclipse DDMS.



Screenshot taken through the solution proposed here: How to programmatically take a screenshot in Android? and in most other SO questions only have View elements visible, but not the SurfaceView.



SCREENSHOTS_LOCATIONS = Environment.getExternalStorageDirectory().toString() + "/screenshots/";
// Get root view
View view = activity.getWindow().getDecorView().getRootView();
// Create the bitmap to use to draw the screenshot
final Bitmap bitmap = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);

// Get current theme to know which background to use
final Theme theme = activity.getTheme();
final TypedArray ta = theme
.obtainStyledAttributes(new int { android.R.attr.windowBackground });
final int res = ta.getResourceId(0, 0);
final Drawable background = activity.getResources().getDrawable(res);

// Draw background
background.draw(canvas);

// Draw views
view.draw(canvas);

// Save the screenshot to the file system
FileOutputStream fos = null;
try {
final File sddir = new File(SCREENSHOTS_LOCATIONS);
if (!sddir.exists()) {
sddir.mkdirs();
}
fos = new FileOutputStream(SCREENSHOTS_LOCATIONS
+ System.currentTimeMillis() + ".jpg");
if (fos != null) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)) {
Log.d("ScreenShot", "Compress/Write failed");
}
fos.flush();
fos.close();
}

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


Any help in this regard would be highly appreciated. Thanks.










share|improve this question

























  • so you want to capture the view that are not visible or are beneath some other view?

    – Nimish Choudhary
    Jan 31 '13 at 7:00











  • Possible duplicate of Android Take Screenshot of Surface View Shows Black Screen

    – Anjani Mittal
    Nov 22 '18 at 11:26














9












9








9


1






I want to programatically take screen shot of my game, just as you'd get in Eclipse DDMS.



Screenshot taken through the solution proposed here: How to programmatically take a screenshot in Android? and in most other SO questions only have View elements visible, but not the SurfaceView.



SCREENSHOTS_LOCATIONS = Environment.getExternalStorageDirectory().toString() + "/screenshots/";
// Get root view
View view = activity.getWindow().getDecorView().getRootView();
// Create the bitmap to use to draw the screenshot
final Bitmap bitmap = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);

// Get current theme to know which background to use
final Theme theme = activity.getTheme();
final TypedArray ta = theme
.obtainStyledAttributes(new int { android.R.attr.windowBackground });
final int res = ta.getResourceId(0, 0);
final Drawable background = activity.getResources().getDrawable(res);

// Draw background
background.draw(canvas);

// Draw views
view.draw(canvas);

// Save the screenshot to the file system
FileOutputStream fos = null;
try {
final File sddir = new File(SCREENSHOTS_LOCATIONS);
if (!sddir.exists()) {
sddir.mkdirs();
}
fos = new FileOutputStream(SCREENSHOTS_LOCATIONS
+ System.currentTimeMillis() + ".jpg");
if (fos != null) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)) {
Log.d("ScreenShot", "Compress/Write failed");
}
fos.flush();
fos.close();
}

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


Any help in this regard would be highly appreciated. Thanks.










share|improve this question
















I want to programatically take screen shot of my game, just as you'd get in Eclipse DDMS.



Screenshot taken through the solution proposed here: How to programmatically take a screenshot in Android? and in most other SO questions only have View elements visible, but not the SurfaceView.



SCREENSHOTS_LOCATIONS = Environment.getExternalStorageDirectory().toString() + "/screenshots/";
// Get root view
View view = activity.getWindow().getDecorView().getRootView();
// Create the bitmap to use to draw the screenshot
final Bitmap bitmap = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);

// Get current theme to know which background to use
final Theme theme = activity.getTheme();
final TypedArray ta = theme
.obtainStyledAttributes(new int { android.R.attr.windowBackground });
final int res = ta.getResourceId(0, 0);
final Drawable background = activity.getResources().getDrawable(res);

// Draw background
background.draw(canvas);

// Draw views
view.draw(canvas);

// Save the screenshot to the file system
FileOutputStream fos = null;
try {
final File sddir = new File(SCREENSHOTS_LOCATIONS);
if (!sddir.exists()) {
sddir.mkdirs();
}
fos = new FileOutputStream(SCREENSHOTS_LOCATIONS
+ System.currentTimeMillis() + ".jpg");
if (fos != null) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos)) {
Log.d("ScreenShot", "Compress/Write failed");
}
fos.flush();
fos.close();
}

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


Any help in this regard would be highly appreciated. Thanks.







android screenshot surfaceview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 12:09









Community

11




11










asked Jan 31 '13 at 6:52









Tariq MahmoodTariq Mahmood

46112




46112













  • so you want to capture the view that are not visible or are beneath some other view?

    – Nimish Choudhary
    Jan 31 '13 at 7:00











  • Possible duplicate of Android Take Screenshot of Surface View Shows Black Screen

    – Anjani Mittal
    Nov 22 '18 at 11:26



















  • so you want to capture the view that are not visible or are beneath some other view?

    – Nimish Choudhary
    Jan 31 '13 at 7:00











  • Possible duplicate of Android Take Screenshot of Surface View Shows Black Screen

    – Anjani Mittal
    Nov 22 '18 at 11:26

















so you want to capture the view that are not visible or are beneath some other view?

– Nimish Choudhary
Jan 31 '13 at 7:00





so you want to capture the view that are not visible or are beneath some other view?

– Nimish Choudhary
Jan 31 '13 at 7:00













Possible duplicate of Android Take Screenshot of Surface View Shows Black Screen

– Anjani Mittal
Nov 22 '18 at 11:26





Possible duplicate of Android Take Screenshot of Surface View Shows Black Screen

– Anjani Mittal
Nov 22 '18 at 11:26












2 Answers
2






active

oldest

votes


















1














I hope this also useful for you. here little difference for the above answer is
for I used glsurfaceview to take the screen shots hen i click the button.
this image is stored in sdcard for mentioned folder :
sdcard/emulated/0/printerscreenshots/image/...images



 My Program :

View view_storelayout ;
view_storelayout = findViewById(R.id.gl_surface_view);

button onclick() {

view_storelayout.setDrawingCacheEnabled(true);

view_storelayout.buildDrawingCache(true);

Bitmap bmp = Bitmap.createBitmap(view_storelayout.getDrawingCache());
view_storelayout.setDrawingCacheEnabled(false); // clear drawing cache
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 90, bos);
byte bitmapdata = bos.toByteArray();
ByteArrayInputStream fis = new ByteArrayInputStream(bitmapdata);

final Calendar c=Calendar.getInstance();
long mytimestamp=c.getTimeInMillis();
String timeStamp=String.valueOf(mytimestamp);
String myfile="hari"+timeStamp+".jpeg";

dir_image=new File(Environment.getExternalStorageDirectory()+
File.separator+"printerscreenshots"+File.separator+"image");
dir_image.mkdirs();

try {
File tmpFile = new File(dir_image,myfile);
FileOutputStream fos = new FileOutputStream(tmpFile);

byte buf = new byte[1024];
int len;
while ((len = fis.read(buf)) > 0) {
fos.write(buf, 0, len);
}
fis.close();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

Toast.makeText(getApplicationContext(), "myPath:"
+dir_image.toString(), Toast.LENGTH_SHORT).show();
Log.v("hari", "screenshots:"+dir_image.toString());

}

Note :
But, here i am faced one problem. In this surfaceview , i drawn line and circle
at runtime. after drawn some objects, when i take screenshots , its stored only for
black image like surfaceview is stored as an image.

And also i want to store that surfaceview image as an .dxf format(autocad format).
i tried to stored image file as an .dxf file format.its saved successfully in
autocad format. but, it cant open in autocad software to edit my .dxf file.





share|improve this answer



















  • 2





    @ harikrishnan..not working save black image

    – Girish Patel
    Mar 12 '15 at 7:19



















1














The code from the Usman Kurd answer will not work is most cases.



Unless you're rendering H.264 video frames in software with Canvas onto a View, the drawing-cache approach won't work (see e.g. this answer).



You cannot read pixels from the Surface part of the SurfaceView. The basic problem is that a Surface is a queue of buffers with a producer-consumer interface, and your app is on the producer side. The consumer, usually the system compositor (SurfaceFlinger), is able to capture a screen shot because it's on the other end of the pipe.



Take Screenshot of SurfaceView






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14620055%2fhow-to-take-a-screenshot-of-androids-surface-view%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I hope this also useful for you. here little difference for the above answer is
    for I used glsurfaceview to take the screen shots hen i click the button.
    this image is stored in sdcard for mentioned folder :
    sdcard/emulated/0/printerscreenshots/image/...images



     My Program :

    View view_storelayout ;
    view_storelayout = findViewById(R.id.gl_surface_view);

    button onclick() {

    view_storelayout.setDrawingCacheEnabled(true);

    view_storelayout.buildDrawingCache(true);

    Bitmap bmp = Bitmap.createBitmap(view_storelayout.getDrawingCache());
    view_storelayout.setDrawingCacheEnabled(false); // clear drawing cache
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bmp.compress(CompressFormat.JPEG, 90, bos);
    byte bitmapdata = bos.toByteArray();
    ByteArrayInputStream fis = new ByteArrayInputStream(bitmapdata);

    final Calendar c=Calendar.getInstance();
    long mytimestamp=c.getTimeInMillis();
    String timeStamp=String.valueOf(mytimestamp);
    String myfile="hari"+timeStamp+".jpeg";

    dir_image=new File(Environment.getExternalStorageDirectory()+
    File.separator+"printerscreenshots"+File.separator+"image");
    dir_image.mkdirs();

    try {
    File tmpFile = new File(dir_image,myfile);
    FileOutputStream fos = new FileOutputStream(tmpFile);

    byte buf = new byte[1024];
    int len;
    while ((len = fis.read(buf)) > 0) {
    fos.write(buf, 0, len);
    }
    fis.close();
    fos.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }

    Toast.makeText(getApplicationContext(), "myPath:"
    +dir_image.toString(), Toast.LENGTH_SHORT).show();
    Log.v("hari", "screenshots:"+dir_image.toString());

    }

    Note :
    But, here i am faced one problem. In this surfaceview , i drawn line and circle
    at runtime. after drawn some objects, when i take screenshots , its stored only for
    black image like surfaceview is stored as an image.

    And also i want to store that surfaceview image as an .dxf format(autocad format).
    i tried to stored image file as an .dxf file format.its saved successfully in
    autocad format. but, it cant open in autocad software to edit my .dxf file.





    share|improve this answer



















    • 2





      @ harikrishnan..not working save black image

      – Girish Patel
      Mar 12 '15 at 7:19
















    1














    I hope this also useful for you. here little difference for the above answer is
    for I used glsurfaceview to take the screen shots hen i click the button.
    this image is stored in sdcard for mentioned folder :
    sdcard/emulated/0/printerscreenshots/image/...images



     My Program :

    View view_storelayout ;
    view_storelayout = findViewById(R.id.gl_surface_view);

    button onclick() {

    view_storelayout.setDrawingCacheEnabled(true);

    view_storelayout.buildDrawingCache(true);

    Bitmap bmp = Bitmap.createBitmap(view_storelayout.getDrawingCache());
    view_storelayout.setDrawingCacheEnabled(false); // clear drawing cache
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bmp.compress(CompressFormat.JPEG, 90, bos);
    byte bitmapdata = bos.toByteArray();
    ByteArrayInputStream fis = new ByteArrayInputStream(bitmapdata);

    final Calendar c=Calendar.getInstance();
    long mytimestamp=c.getTimeInMillis();
    String timeStamp=String.valueOf(mytimestamp);
    String myfile="hari"+timeStamp+".jpeg";

    dir_image=new File(Environment.getExternalStorageDirectory()+
    File.separator+"printerscreenshots"+File.separator+"image");
    dir_image.mkdirs();

    try {
    File tmpFile = new File(dir_image,myfile);
    FileOutputStream fos = new FileOutputStream(tmpFile);

    byte buf = new byte[1024];
    int len;
    while ((len = fis.read(buf)) > 0) {
    fos.write(buf, 0, len);
    }
    fis.close();
    fos.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }

    Toast.makeText(getApplicationContext(), "myPath:"
    +dir_image.toString(), Toast.LENGTH_SHORT).show();
    Log.v("hari", "screenshots:"+dir_image.toString());

    }

    Note :
    But, here i am faced one problem. In this surfaceview , i drawn line and circle
    at runtime. after drawn some objects, when i take screenshots , its stored only for
    black image like surfaceview is stored as an image.

    And also i want to store that surfaceview image as an .dxf format(autocad format).
    i tried to stored image file as an .dxf file format.its saved successfully in
    autocad format. but, it cant open in autocad software to edit my .dxf file.





    share|improve this answer



















    • 2





      @ harikrishnan..not working save black image

      – Girish Patel
      Mar 12 '15 at 7:19














    1












    1








    1







    I hope this also useful for you. here little difference for the above answer is
    for I used glsurfaceview to take the screen shots hen i click the button.
    this image is stored in sdcard for mentioned folder :
    sdcard/emulated/0/printerscreenshots/image/...images



     My Program :

    View view_storelayout ;
    view_storelayout = findViewById(R.id.gl_surface_view);

    button onclick() {

    view_storelayout.setDrawingCacheEnabled(true);

    view_storelayout.buildDrawingCache(true);

    Bitmap bmp = Bitmap.createBitmap(view_storelayout.getDrawingCache());
    view_storelayout.setDrawingCacheEnabled(false); // clear drawing cache
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bmp.compress(CompressFormat.JPEG, 90, bos);
    byte bitmapdata = bos.toByteArray();
    ByteArrayInputStream fis = new ByteArrayInputStream(bitmapdata);

    final Calendar c=Calendar.getInstance();
    long mytimestamp=c.getTimeInMillis();
    String timeStamp=String.valueOf(mytimestamp);
    String myfile="hari"+timeStamp+".jpeg";

    dir_image=new File(Environment.getExternalStorageDirectory()+
    File.separator+"printerscreenshots"+File.separator+"image");
    dir_image.mkdirs();

    try {
    File tmpFile = new File(dir_image,myfile);
    FileOutputStream fos = new FileOutputStream(tmpFile);

    byte buf = new byte[1024];
    int len;
    while ((len = fis.read(buf)) > 0) {
    fos.write(buf, 0, len);
    }
    fis.close();
    fos.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }

    Toast.makeText(getApplicationContext(), "myPath:"
    +dir_image.toString(), Toast.LENGTH_SHORT).show();
    Log.v("hari", "screenshots:"+dir_image.toString());

    }

    Note :
    But, here i am faced one problem. In this surfaceview , i drawn line and circle
    at runtime. after drawn some objects, when i take screenshots , its stored only for
    black image like surfaceview is stored as an image.

    And also i want to store that surfaceview image as an .dxf format(autocad format).
    i tried to stored image file as an .dxf file format.its saved successfully in
    autocad format. but, it cant open in autocad software to edit my .dxf file.





    share|improve this answer













    I hope this also useful for you. here little difference for the above answer is
    for I used glsurfaceview to take the screen shots hen i click the button.
    this image is stored in sdcard for mentioned folder :
    sdcard/emulated/0/printerscreenshots/image/...images



     My Program :

    View view_storelayout ;
    view_storelayout = findViewById(R.id.gl_surface_view);

    button onclick() {

    view_storelayout.setDrawingCacheEnabled(true);

    view_storelayout.buildDrawingCache(true);

    Bitmap bmp = Bitmap.createBitmap(view_storelayout.getDrawingCache());
    view_storelayout.setDrawingCacheEnabled(false); // clear drawing cache
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bmp.compress(CompressFormat.JPEG, 90, bos);
    byte bitmapdata = bos.toByteArray();
    ByteArrayInputStream fis = new ByteArrayInputStream(bitmapdata);

    final Calendar c=Calendar.getInstance();
    long mytimestamp=c.getTimeInMillis();
    String timeStamp=String.valueOf(mytimestamp);
    String myfile="hari"+timeStamp+".jpeg";

    dir_image=new File(Environment.getExternalStorageDirectory()+
    File.separator+"printerscreenshots"+File.separator+"image");
    dir_image.mkdirs();

    try {
    File tmpFile = new File(dir_image,myfile);
    FileOutputStream fos = new FileOutputStream(tmpFile);

    byte buf = new byte[1024];
    int len;
    while ((len = fis.read(buf)) > 0) {
    fos.write(buf, 0, len);
    }
    fis.close();
    fos.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }

    Toast.makeText(getApplicationContext(), "myPath:"
    +dir_image.toString(), Toast.LENGTH_SHORT).show();
    Log.v("hari", "screenshots:"+dir_image.toString());

    }

    Note :
    But, here i am faced one problem. In this surfaceview , i drawn line and circle
    at runtime. after drawn some objects, when i take screenshots , its stored only for
    black image like surfaceview is stored as an image.

    And also i want to store that surfaceview image as an .dxf format(autocad format).
    i tried to stored image file as an .dxf file format.its saved successfully in
    autocad format. but, it cant open in autocad software to edit my .dxf file.






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 5 '13 at 10:08









    harikrishnanharikrishnan

    1,06722150




    1,06722150








    • 2





      @ harikrishnan..not working save black image

      – Girish Patel
      Mar 12 '15 at 7:19














    • 2





      @ harikrishnan..not working save black image

      – Girish Patel
      Mar 12 '15 at 7:19








    2




    2





    @ harikrishnan..not working save black image

    – Girish Patel
    Mar 12 '15 at 7:19





    @ harikrishnan..not working save black image

    – Girish Patel
    Mar 12 '15 at 7:19













    1














    The code from the Usman Kurd answer will not work is most cases.



    Unless you're rendering H.264 video frames in software with Canvas onto a View, the drawing-cache approach won't work (see e.g. this answer).



    You cannot read pixels from the Surface part of the SurfaceView. The basic problem is that a Surface is a queue of buffers with a producer-consumer interface, and your app is on the producer side. The consumer, usually the system compositor (SurfaceFlinger), is able to capture a screen shot because it's on the other end of the pipe.



    Take Screenshot of SurfaceView






    share|improve this answer






























      1














      The code from the Usman Kurd answer will not work is most cases.



      Unless you're rendering H.264 video frames in software with Canvas onto a View, the drawing-cache approach won't work (see e.g. this answer).



      You cannot read pixels from the Surface part of the SurfaceView. The basic problem is that a Surface is a queue of buffers with a producer-consumer interface, and your app is on the producer side. The consumer, usually the system compositor (SurfaceFlinger), is able to capture a screen shot because it's on the other end of the pipe.



      Take Screenshot of SurfaceView






      share|improve this answer




























        1












        1








        1







        The code from the Usman Kurd answer will not work is most cases.



        Unless you're rendering H.264 video frames in software with Canvas onto a View, the drawing-cache approach won't work (see e.g. this answer).



        You cannot read pixels from the Surface part of the SurfaceView. The basic problem is that a Surface is a queue of buffers with a producer-consumer interface, and your app is on the producer side. The consumer, usually the system compositor (SurfaceFlinger), is able to capture a screen shot because it's on the other end of the pipe.



        Take Screenshot of SurfaceView






        share|improve this answer















        The code from the Usman Kurd answer will not work is most cases.



        Unless you're rendering H.264 video frames in software with Canvas onto a View, the drawing-cache approach won't work (see e.g. this answer).



        You cannot read pixels from the Surface part of the SurfaceView. The basic problem is that a Surface is a queue of buffers with a producer-consumer interface, and your app is on the producer side. The consumer, usually the system compositor (SurfaceFlinger), is able to capture a screen shot because it's on the other end of the pipe.



        Take Screenshot of SurfaceView







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited May 23 '17 at 11:53









        Community

        11




        11










        answered Dec 16 '15 at 14:22









        Kirill VashiloKirill Vashilo

        762921




        762921






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14620055%2fhow-to-take-a-screenshot-of-androids-surface-view%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith