如何保存在web视图中显示的图像? [英] how to save images displayed in webview?

查看:202
本文介绍了如何保存在web视图中显示的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要救显示的WebView到本地存储的图像和web视图应该缓存它显示的图像,我怎么能访问缓存图像,并将它们保存到存储?

解决方案

 的WebView web视图=新的WebView(本);
//你的形象在web视图

画中画= webView.capturePicture();
帆布油画=新的Canvas();
picture.draw(画布);
位图图像= Bitmap.createBitmap(picture.getWidth()
picture.getHeight(),Config.ARGB_8888);
canvas.drawBitmap(mimage,0,0,NULL);
如果(图像!= NULL){
    ByteArrayOutputStream mByteArrayOS =新
    ByteArrayOutputStream();
    image.com preSS(Bitmap.Com pressFormat.JPEG,90,mByteArrayOS);
    尝试 {
        FOS = openFileOutput(image.jpg文件,MODE_WORLD_WRITEABLE);
        fos.write(mByteArrayOS.toByteArray());
        fos.close();
    }赶上(FileNotFoundException异常E){
        e.printStackTrace();
    }赶上(IOException异常E){
        e.printStackTrace();
    }
}
 

尝试上面从web视图捕获图像

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

这篇关于如何保存在web视图中显示的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆