1

I used Google chart api to generate the chart using webview in android. Now my next requirement is to save that image into some local storage and to send the image via email and mms.please help me in doing that.

thanks nishant

Nishant
  • 32,082
  • 5
  • 39
  • 53

1 Answers1

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();
         }
 }

And for sending the images thro email u can go thru this question
and for MMS

Community
  • 1
  • 1
Hussain
  • 5,552
  • 4
  • 40
  • 50
  • Thanks for quick reply. I used the above code but it is throwing exception while creating the Bitmap saying java.lang.IllegalArgumentException: width and height must be > 0. I had given the dimension 250*100 as a parameter to google Chart API. – Nishant Jul 08 '11 at 06:34
  • Ur problem maybe on `CaptureImage()`,check whether it is fetchin the image from the chart. Then try it out. cheers – Hussain Jul 08 '11 at 06:42
  • Go thro' this link http://stackoverflow.com/questions/5454242/android-bitmapfactrory-cuts-off-image – Hussain Jul 08 '11 at 06:53
  • please help me i am not able to retrieve the image from google chart api – Nishant Jul 08 '11 at 08:29
  • I retrieved and saved the image using the code in the link which you has provided thanks hussain. – Nishant Jul 08 '11 at 08:48
  • @Nishant: Good :) Cheers.. Consider urself accepting the answer if u think it helped for u.. – Hussain Jul 08 '11 at 09:05