问题
I have a webview and I capture the view like this
Picture picture = m_browser.capturePicture();
Bitmap b = Bitmap.createBitmap( picture.getWidth(),
picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas( b );
picture.draw( c );
FileOutputStream fos = null;
try {
fos = new FileOutputStream("/sdcard/temp_1.jpg");
//fos = openFileOutput("samsp_1.jpg", MODE_WORLD_WRITEABLE);
if ( fos != null )
{
b.compress(Bitmap.CompressFormat.JPEG,90, fos);
fos.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Now if the loaded web site is long, for eg. times.com then this image is also too big.
I want to split this image in multiple images and with out reducing the quality.
I would like to get these images in the highest quality possible.
Pls. help Thanks
回答1:
It's a bit of a hack, but this will work on VERY long webpages without running out of memory. First, put your webview inside another layout (RelativeLayout rl). Size the RelativeLayout for the image size you want. Then call:
rl.draw(canvas);
// do something here to save your bitmap
webview.scrollby(0, rl.getHeight());
and repeat that till you're at the bottom of the page!
回答2:
Bitmap.createBitmap(source, x, y, width, height)
I allways use this code to cut the a large image to multiple images.
I can use it easy
来源:https://stackoverflow.com/questions/3465146/android-how-to-split-picture-captured-from-webview-in-multiple-images