Here when i problem convert view to image in android then i am facing an error and close the application but when i write hardcoded fields for createbitmap function then it save black image in sd card …
public static Bitmap loadBitmapFromView (View v) {
Bitmap b,bitmap;
int iwidth = 1435;
int iheight=435;
try
{b = Bitmap.createBitmap(iwidth, iheight, Bitmap.Config.ARGB_8888);
//error in next line
b = Bitmap.createBitmap( v.getWidth(), v.getHeight(),Bitmap.Config.ARGB_8888);
return b;
}
catch (Exception e) {
Log.v("error", e.getMessage());
return bitmap=null;
}
Um, some shots in the dark:
-Are you sure the view is not null and has a width and height that you can retrieve at the time of the call? I would have a check for that at the beginning- throw an error or return a null if the View v is null.
-The method getWidth() returns a final int. I’m not a java expert but maybe that is messing something up, so try setting iwidth and iheight to getWidth() and getHeight() and then see if it works.