Webview Capturing Causes Out Of Memory Exception
i am loading html data into webview , after that i need to capture webview data and stored that image into sd card. Its working fine for small images, but it gives out of memory ex
Solution 1:
like @varan said, try to decode the image:
publicstatic Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensionsfinal BitmapFactory.Optionsoptions=newBitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
publicstaticintcalculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of imagefinalintheight= options.outHeight;
finalintwidth= options.outWidth;
intstretch_width= Math.round((float)width / (float)reqWidth);
intstretch_height= Math.round((float)height / (float)reqHeight);
if (stretch_width <= stretch_height) return stretch_height;
elsereturn stretch_width;
}
I don't know how to do it in your special case from Picture to Bitmap, so if someone else knows feel free to edit this post.
Post a Comment for "Webview Capturing Causes Out Of Memory Exception"