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

时间:2011-07-08 04:29:31

标签: android

我使用Google chart api在android中使用webview生成图表。现在我的下一个要求是将该图像保存到一些本地存储中,并通过电子邮件和mms.please发送图像,帮助我做到这一点。

感谢 NISHANT

1 个答案:

答案 0 :(得分:3)

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