konik32
konik32

Reputation: 41

Creating image of layout

Is it possible to create image of layout? I have a GridView composed of 25 ImageViews. I want save GridView as an image and display it later on ImageView. Is it possible?

Upvotes: 3

Views: 2003

Answers (1)

jkhouw1
jkhouw1

Reputation: 7350

this will create an image of the view

public static Bitmap loadBitmapFromView(View v) {   
    Bitmap b = Bitmap.createBitmap( 
        v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);           
         Canvas c = new Canvas(b);
         v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
         v.draw(c);   
      return b;
     }

pass it your layout, and save the returned bitmap as a file somewhere.

Upvotes: 5

Related Questions