android - IllegalArgumentException while taking a screen shot of a custom view -
while trying make screen shot of custom view,i got illegalargumentexception : width , height must >0
. here wrote :
bitmap = loadbitmapfromview(v1);//v1 custom view want picture. 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; }
the line in there exception : bitmap b = bitmap.createbitmap( v.getlayoutparams().width, v.getlayoutparams().height, bitmap.config.argb_8888);
of course screen shot code executed after view showed,on next_act button code
the width , height of layoutparams
can constant such fill_parent
, , negative numbers.
to view's measured dimensions can use:
v.getmeasuredwidth() , v.getmeasuredheight()
however, depends on you're after, , whether view has been measured.
it make more sense wait until view has been drawn, before taking screenshot ;-) you'd need explain more use case.
Comments
Post a Comment