Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Picture.writeToStream() not writing out all bitmaps

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.

like image 723
quickdraw mcgraw Avatar asked Aug 19 '10 11:08

quickdraw mcgraw


1 Answers

That's the way the API is meant to work. It was never intended for long term storage, but to store flattened in the current process, or to send to another process. What you are asking for will not be supported.

like image 88
Romain Guy Avatar answered Nov 15 '22 19:11

Romain Guy