Picture.writeToStream()不是写出来的所有位图位图、不是、Picture、writeToStream

2023-09-05 07:20:22 作者:望天边星宿

我使用的 webview.capturePicture() 的创建一个包含所有网页的图形对象一个图片对象。

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

我可以成功地使用的 canvas.drawPicture(图片,DST) 的,没有任何问题呈现此图片对象为位图。 然而,当我使用的 picture.writeToStream(FOS) 的序列化的图片对象出到文件中,然后 Picture.createFromStream(FIS) 的读取数据回,并创建一个新的图片对象,如上呈现时所产生的位图缺少任何较大图像(任何超过20KB左右!通过观察)。

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).

这发生的一切,我已经测试过1.5,1.6和2.1的Andr​​oid操作系统平台。 综观本土$ C $下的 Skia的 的是底层Android的图形库,并从的 picture.writeToStream() 的我可以看到文件格式构造。 我可以看到一些在此Skia的假脱机文件中的图像都没有被写入了(大的),这似乎是这个问题是在code的 skBitmap.cpp 的的方法

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;

它写出了位图的 fWidth,fHeight,fRowBytes,FConfig和的isOpaque 的值,但当时只是写出来的 SERIALIZE_PIXELTYPE_NONE(0)。 的这意味着该假脱机文件不包含有关实际图像中的任何像素信息,因此不能正确地恢复图像对象​​

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.

这实际上将呈现的 writeToStream和createFromStream() 的原料药没用,因为他们不可靠的存储和再现图像数据。

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

有其他人看到这种行为,如果是这样我是使用API​​不正确,可以在周围的工作,有一个解释,即不完整的API /错误,如果是在Android系统未来的版本有什么计划修复?

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?

在此先感谢。

推荐答案

在蜂巢平台似乎writeToStream()和createFromStream()现在存储和再现包括大型图像数据的图像对象。

On the Honeycomb platform it appears that writeToStream() and createFromStream() now store and recreate the Picture object including large image data.

不过它并配有以下注意事项:

However it does come with the following caveats:

在一个画面中使用的图像数据必须是不可变的类型。 的图像数据必须已创建设置为true,inInputShareable和inPurgeable以下BitmapFactory.Options。这可以通过使用BitmapFactory.de codeResource()传入BitmapFactory.Options进行。

事实上,有图片由web视图创建'做'包含满足此条件,因此可以被序列化并恢复合适的图像。

It so happens that Pictures created by WebView 'do' contain suitable images that meet this criteria and therefore can be serialized and restored.

我还没有证实的还以为冰淇淋三明治也适用,但我假设/希望它会。

I have not confirmed as yet that Ice Cream Sandwich also works but I am assuming/hoping that it will.