2

I know I can look at the source, but I'm wondering if there's any documentation for the format used by android.graphics.Picture.writeToStream(OutputStream).

Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
  • You can find some insights from another programmer here: http://stackoverflow.com/questions/3521299/picture-writetostream-not-writing-out-all-bitmaps – Lars Blumberg Apr 03 '11 at 16:51
  • @Lars Thanks. From Romain Guy's answer on that question I can kind of infer that I shouldn't be using Picture's serialization for what I want, though I have to say that's not what I was hoping for. – Laurence Gonsalves Apr 03 '11 at 21:46

2 Answers2

2

I would guess that it is the same as the format of all these "skp" files here:

http://skia.googlecode.com/svn/skp/

Which you can open with the Skia Debugger which is included in skia (if you can get it to compile!).

Having said that, the skia debugger segfaulted when I tried to open the output of writeToStream() for my test view.

Code details

This is the function the Android code calls through to. As you can see it is versioned. The test files in that directory are version 9. The output of Canvas.writeToStream() on my Galaxy S2 is version 1. Here is where the java code calls through to:

http://code.google.com/p/skia/source/browse/trunk/src/core/SkPicture.cpp#291

But that is obviously a way newer version than the one on my phone, since it is version 9:

http://code.google.com/p/skia/source/browse/trunk/include/core/SkPicture.h#161

The pictures are restored using SkPicture's constructor which isn't backwards compatible:

http://code.google.com/p/skia/source/browse/trunk/src/core/SkPicture.cpp#269

Which is a bit of a shame and makes it quite hacky to use as a serialization format since you'll have to sniff the PICTURE_VERSION on Android and then do funky stuff to give Android the right version.

Edit

The PICTURE_VERSION is 1 up to and including ICS, and 2 in Jellybean:

https://github.com/android/platform_external_skia/blob/master/include/core/SkUserConfig.h#L44

Timmmm
  • 88,195
  • 71
  • 364
  • 509
2

You could check out SkPictureRecord.cpp. It looks like the details of drawing functions are simply serialized linearly via methods like:

void addScalar(SkScalar scalar) {
    fWriter.writeScalar(scalar);
}

In any case, as with most private details of the SDK, leveraging this knowledge is likely to get you into trouble when the SDK changes.

Matthew
  • 44,826
  • 10
  • 98
  • 87
  • 1
    Yeah, this is part of the reason why I'm asking if it's documented. I need a way to store vector graphics as part of an Android application. Using the Picture serialization mechanism would probably give me the best performance given that it's native code, and it'd also be less code I'd have to actually ship as part of my app, but I'd rather not be so dependent upon undocumented behavior. – Laurence Gonsalves Apr 03 '11 at 21:43
  • Hmm... yes, this is highly undocumented. You might anyways want to have a higher-level representation of your vector graphics so that you can do layers etc. – Matthew Apr 04 '11 at 01:19