How to convert an activity to an image

I have an activity with some views, after doing some actions, I want to convert the appearance of this activity to an image and send it via email. I can send an image by email, but how can I make this activity into an image? Is it possible?


source to share

2 answers

You can programmatically take a screenshot of your device, which should do the trick. Take a look at this SO answer> it should get you started.



You can map different views of your application to Bitmap

Objects by capturing drawing cache


just refer to for more details. (thanks, for a great tutorial)


private Bitmap getScreenViewBitmap(View v) {

    // this is the important code :)  
    // Without it the view will have a dimension of 0,0 and the bitmap will be null          
    v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); 

    Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
    v.setDrawingCacheEnabled(false); // clear drawing cache


it seems that you are interested. (Just find your top level view and use this method to capture Bitmap)



All Articles