Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to save images displayed in webview?

Tags:

android

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?

like image 788
jerry stone Avatar asked Apr 15 '12 03:04

jerry stone


1 Answers

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

like image 112
Shankar Agarwal Avatar answered Nov 15 '22 00:11

Shankar Agarwal