gpt4 book ai didi

android - 将图像从 webview 保存到某个文件夹

转载 作者:行者123 更新时间:2023-11-29 18:18:52 26 4
gpt4 key购买 nike

我使用 Google chart api 在 android 中使用 webview 生成图表。现在我的下一个要求是将该图像保存到某个本地存储中并通过电子邮件和彩信发送图像。请帮助我完成这项工作。

谢谢尼尚

最佳答案

WebView w = new WebView(this);
//Loads the url
w.loadUrl("http://www.yahoo.com";);
//After loading completely, take its picture
Picture picture = w.capturePicture();
//Create a new canvas
Canvas mCanvas = new Canvas();
//Draw the Picture into the Canvas
picture.draw(mCanvas);
//Create a Bitmap
Bitmap sreenshot = Bitmap.createBitmap(picture.getWidth(),
picture.getHeight(),Config.ARGB_8888);
//copy the content fron Canvas to Bitmap
mCanvas.drawBitmap(mBitmapScreenshot, 0, 0, null);

//Save the Bitmap to local filesystem
if(sreenshot != null) {
ByteArrayOutputStream mByteArrayOpStream = new
ByteArrayOutputStream();
screenshot.compress(Bitmap.CompressFormat.JPEG, 90,
mByteArrayOpStream);
try {
fos = openFileOutput("yahoo.jpg",
MODE_WORLD_WRITEABLE);
fos.write(mByteArrayOpStream.toByteArray());
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

要通过电子邮件发送图像,您可以通过此 question
MMS

关于android - 将图像从 webview 保存到某个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6619989/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com