0

I am trying to write a method in android to save the whole webview as an image as following:

    bitmap = Bitmap.createBitmap(webView.getWidth(),
        Math.round(webView.getContentHeight() * webView.getScale()), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    webView.draw(canvas);
    FileOutputStream out = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.JPEG, JPEG_COMPRESSION, out);

However, the bitmap is too big (more than 100 MB) and takes too much memory. Does anyone know any better method to keep the memory usage low? The problem is the WebView is small, and the generated JPEG file is small but the intermediate Bitmap which is not used any more in other places is huge.

1 Answers1

0

Set JPEG_COMPRESSION = 0-100 as it is a quality paramater of bitmap 0 meaning compress for small size, 100 meaning compress for max quality.

You can also set bitmap height and width using BitmapFactory.Options bop

bop.outWidth

bop.outHeight

Abhijeet
  • 392
  • 2
  • 13
  • The size of JPEG file is acceptable, however the intermediate bitmap is too big. I am thinking cutting the bitmap into pieces and compress the pieces one by one, but I can't find any method to concatenate them together in JPEG form. – Jerome Wang Jul 09 '15 at 18:09