1

I'm trying to get a image from a web view, but, when I call the "webView.capturePicture()" it bring me a Picture Object. In most cases this is enough to me use the follow code to convert it to a bitmap object

Bitmap b = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
picture.draw(c);

But in same cases the Bitmap that will be created is largest than the android supports on memory.

So, I need to know how to convert the Picture object to bitmap Object directly in a File (I guess that would be a solution) without any instance of Bitmap in Memory. Or same like that. The main point is create a bitmap from the picture object, but I can't because it's too large.

PS: I don't want to use ' android:largeHeap="true" '.

So if someone have same idea let me know.

Thanks

Carlos EduardoL
  • 670
  • 6
  • 14

1 Answers1

0

try this:

Picture p = webView.capturePicture();  
FileOutputStream fos;

try {
   fos = new FileOutputStream("/sdcard/picture");
   p.writeToStream(fos);
   fos.flush();
   fos.close();
} catch (FileNotFoundException e) {
   e.printStackTrace();
} catch (IOException e) {
   e.printStackTrace();
}  

Warning: Picture.writeToStream() is deprecated from api level 18. And the suggested alternative is to create a bitmap. More info here

Mohan Krishna
  • 352
  • 3
  • 15