Hi,
I'm loading transparent PNGs into bitmaps using two different methods.
The first being BitmapFactory.decodeStream() of a resource stream. The
second being Bitmap.createBitmap(), populated by a Bitmap.setPixels()
call.
When drawn on a canvas, the bitmaps loaded by decodeStream() perform
significantly better. At first I thought the difference might be due
to using a createBitmap() overload that returns a mutable bitmap, but
changing it to return an immutable bitmap did not cover the difference
in performance.
Calling getConfig() on the bitmaps returned by decodeStream() returns
null, could the bitmap have been converted to an ARGB1555 or similar
format internally? Is it possible to get the same configuration using
createBitmap() with setPixels()?
// Method A ~55FPS
BitmapFactory.Options sBitmapOptions
= new BitmapFactory.Options();
sBitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
InputStream is = context.getResources().openRawResource(resource_id);
Bitmap bitmap = BitmapFactory.decodeStream(is, null, sBitmapOptions);
// Method B ~45FPS
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
int length = (width*height);
int[] arrColor = new int[length];
// fill arrColor
bitmap.setPixels(arrColor, 0, width, 0, 0, width, height);
Thanks
--
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