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.

-------------Problems Reply------------

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.

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:

  • The image data used in a picture must be of an immutable type.
  • The image data must have been created with the following BitmapFactory.Options set to true, inInputShareable and inPurgeable. This can be done by using BitmapFactory.decodeResource() passing in the BitmapFactory.Options.

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.

Category:java Views:1 Time:2010-08-19

Related post

  • Writing to Drawing.Bitmap object instead of a physical file 2009-03-26

    I have a graphics library from a third party that has a method which creates a bitmap inside a folder. I want this method to write to a Drawing.Bitmap object instead of a physical file. Can I do this in .net I am using C# 1.1 thanks. --------------So

  • Writing binary files C++, way to force something to be at byte 18? 2010-08-08

    I'm currently trying to write a .bmp file in C++ and for the most part it works, there is however, just one issue. When I start trying to save images with different widths and heights everything goes askew and I'm struggling to solve it, so is there

  • How to push pixels faster on the iPhone? 2008-10-11

    I asked before about pixel-pushing, and have now managed to get far enough to get noise to show up on the screen. Here's how I init: CGDataProviderRef provider; bitmap = malloc(320*480*4); provider = CGDataProviderCreateWithData(NULL, bitmap, 320*480

  • Why am I getting this generic, non-descript error in GDI+ when trying to save a PNG? 2009-02-04

    I have a function that dynamically adds text to an image in a predesignated spot. Originally I did it with jpegs, and it was working. I switched to PNG so the images would be better quality, as the original jpegs were kind of pixely. Anyway, here is

  • Reading Pixels of Image in C++ 2009-12-16

    How to open and read the pixels of an image in c++? Read them in the form of X, Y and to know the color. --------------Solutions------------- If you are going to be working with images you should look into the OpenCV library, it has pretty much every

  • How to get the "real" colors when exporting a GDI drawing to bmp 2010-05-03

    I'm developing a ASP.Net web handler that returns images making a in-memory System.Windows.Forms.Control and then exports the rendered control as a bitmap compressed to PNG, using the method DrawToBitmap(). The classes are fully working by now, excep

  • How do you display a pixel of color C to iPhone coordinates (x, y)? 2010-05-21

    I've read all Apple documentation on the iPhone development and there's nothing that describes how to do it. --------------Solutions------------- The drawing on iPhone is not pixel-oriented in this way. You can draw a rectangle of size 1x1 using the

  • Get Pixel Values from Android Canvas 2010-07-09

    I'm currently writing an Android game using surfaceView. I've optimized the game as much as possible and it runs quite smoothly. However, I have collision detection incorporated which is a bit messy. I would like to do collision detection by reading

  • Set individual pixels in .NET Format16bppGrayScale image 2010-08-13

    I'm trying to render a small Bitmap in memory with .NET that needs to be 16 bit Grayscale. The bitmap's format is set to PixelFormat.Format16bppGrayScale. However, Bitmap.SetPixel takes a Color argument. Color in turn takes one byte for each of R, B,

  • Graphics performance optimization issue 2010-09-09

    Here's the problem : I need to scroll a huge image of a wave form that has been rendered previously, WPF didn't let me assign that huge (80000*256) picture to an Image, it works for smaller (30000*256) images but it's so slow animating it that it's u

  • Fast drawing lots of rectangles one at a time in WPF 2010-12-15

    My application is fed data from an external device. After each data point, there is a short electronic dead time (of about 10µs) in which no other data point can arrive, which my application should use to process and display the data on screen in a s

  • Concepts about Android Drawable 2011-04-01

    How to get a well understanding the concept of the classes of Canvas,Drawable,Bitmap and Paint? What's the relationship among them ? Could someone please give me an example? Thanks a lot. --------------Solutions------------- Please Visit this link. T

  • android - How to merge and move text around on image 2011-05-05

    hi Here's what i want to do. - Open a jpg in full screen. - Type text on the jpg. - able to move that text where i want it positioned on the bitmap. - moving of text must be done with a finger (not in code). kind of like creating a personal funny Chr

  • Run Android OpenGL in Background as Rendering Resource for App? 2011-06-29

    I want to run an Android OpenGL-ES surface in the background of my app to provide dynamic graphical resources (bitmaps, etc.) for the application. The OpenGl GLSurfaceView is not the visible screen of my app; it is only used as a rendering factory to

  • Android - canvas drawing doubts 2011-10-08

    I am looking at one of the sample applications from Google, which deals with touch drawing using canvas: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TouchPaint.html I have a few doubts: I am not able

  • How does Android memory allocation work with ImageView? 2012-01-06

    I'm loading approximately 20 pictures of size 50-70K from server, then display them in a ListView. Initially I stored the data as Bitmap which causes memory running out quickly. Then I decided to compress all these bitmap files and store in Content p

  • Writing Bitmap Image to File 2014-12-15

    I'm trying to read in a bitmap image from one file and write it to another just to check that the contents were transferred. However when I run my code, the image doesn't get created into the output file. Instead, whenever I click on the new file it

  • problem writing bitmap file header in C 2010-09-09

    I am trying to create a new bitmap file using C. This is a struct for the .bmp file header. #define uint16 unsigned short #define uint32 unsigned long #define uint8 unsigned char typedef struct { uint16 magic; //specifies the file type "BM" 0x424d ui

  • Writing Bitmap to string insted of FILE* or XImage to PNG 2010-12-16

    i converted the output XImage of my code to Bitmap, but the output file is massive, so i thought about compressing it using lzrw i use this code to write the bitmap to file fwrite(&bmpFileHeader, sizeof(bmpFileHeader), 1, fp); fwrite(&bmpInfo

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.136 (s). 11 q(s)