I want to save the images displayed in webview into local storage, and webview should have cached the images it displays ,how can i access the cached images and save them into storage?
WebView webView = new WebView(this);
//your image is in webview
Picture picture = webView.capturePicture();
Canvas canvas = new Canvas();
picture.draw(canvas);
Bitmap image = Bitmap.createBitmap(picture.getWidth(),
picture.getHeight(),Config.ARGB_8888);
canvas.drawBitmap(mimage, 0, 0, null);
if(image != null) {
ByteArrayOutputStream mByteArrayOS = new
ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 90, mByteArrayOS);
try {
fos = openFileOutput("image.jpg", MODE_WORLD_WRITEABLE);
fos.write(mByteArrayOS.toByteArray());
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
try the above to capture image from webView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With