我想将webview中显示的图片保存到本地存储,webview应该已经缓存了它显示的图片,如何访问缓存的图片并将它们保存到本地存储中?
最佳答案
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();
}
}
尝试上面的方法从 webView 捕获图像
关于android - 如何保存在 webview 中显示的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10159247/