Picture.writeToStream() not writing out all bitmaps

Posted by quickdraw mcgraw on Stack Overflow See other posts from Stack Overflow or by quickdraw mcgraw
Published on 2010-08-19T11:33:25Z Indexed on 2011/02/26 7:25 UTC
Read the original article Hit count: 154

Filed under:
|
|

I'm using webview.capturePicture() to create a Picture object that contains all the drawing objects for a webpage.

I can successfully render this Picture object to a bitmap using the canvas.drawPicture(picture, dst) with no problems. However when I use picture.writeToStream(fos) to serialize the picture object out to file, and then Picture.createFromStream(fis) to read the data back in and create a new picture object, the resultant bitmap when rendered as above is missing any larger images (anything over around 20KB! by observation).

This occurs on all the Android OS platforms that I have tested 1.5, 1.6 and 2.1. Looking at the native code for Skia which is the underlying Android graphics library and the output file produced from the picture.writeToStream() I can see how the file format is constructed. I can see that some of the images in this Skia spool file are not being written out (the larger ones), the code that appears to be the problem is in skBitmap.cpp in the method

void SkBitmap::flatten(SkFlattenableWriteBuffer& buffer) const;

It writes out the bitmap fWidth, fHeight, fRowBytes, FConfig and isOpaque values but then just writes out SERIALIZE_PIXELTYPE_NONE (0). This means that the spool file does not contain any pixel information about the actual image and therefore cannot restore the picture object correctly.

Effectively this renders the writeToStream and createFromStream() APIs useless as they do not reliably store and recreate the picture data.

Has anybody else seen this behaviour and if so am I using the API incorrectly, can it be worked around, is there an explanation i.e. incomplete API / bug and if so are there any plans for a fix in a future release of Android?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about java

Related posts about android