My app needs to save some data to a file. Part of that data includes
two bitmaps. So when saving, I use :
bitmapThumbnail.compress(CompressFormat.PNG, 100, streamBuffer);
m_bitmap.compress(CompressFormat.PNG, 100, streamBuffer);
then, when loading, I just want to recreate the two bitmaps from the
data, using :
Bitmap bitmapThumbnail = BitmapFactory.decodeStream(streamBuffer);
Bitmap bitmapTemp = BitmapFactory.decodeStream(streamBuffer);
But for some reason, the second bitmap can never be recreated on load.
BitmapFactory always returns null. I tried the following on save :
bitmapThumbnail.compress(CompressFormat.PNG, 100, streamBuffer);
streamBuffer.writeInt(SECTION_MARKER);
streamBuffer.flush();
m_bitmap.compress(CompressFormat.PNG, 100, streamBuffer);
And then on load, I do :
Bitmap bitmapThumbnail = BitmapFactory.decodeStream(streamBuffer);
int section = streamBuffer.readInt();
if (section != SECTION_MARKER)
throw new IOException();
Bitmap bitmapTemp = BitmapFactory.decodeStream(streamBuffer);
Sure enough, the section marker I read is not the one I had saved. It
seems as if BitmapFactory::decodeStream does not read exactly the same
amount of data as was written by Bitmap::compress.
the bitmaps are 64x64 and 512x512 respectively.
I would be fine with saving the raw bitmap data myself, but Bitmap
takes an array of integers for getting/setting the pixels, and the
stream classes take arrays of bytes for saving/loading, which would
mean I would have to manually copy them around, which is wasteful.
Surely there is an easier way to achieve this ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---