Skip to content Skip to sidebar Skip to footer

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:

    public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
        int reqWidth, int reqHeight) {

        // First decode with inJustDecodeBounds=true to check dimensions
        final BitmapFactory.Options options = new BitmapFactory.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);
}

    public static int calculateInSampleSize(
        BitmapFactory.Options options, int reqWidth, int reqHeight) {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;

        int stretch_width = Math.round((float)width / (float)reqWidth);
        int stretch_height = Math.round((float)height / (float)reqHeight);

        if (stretch_width <= stretch_height) return stretch_height;
        else return 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"