11

I'm making several calls to BitmapFactory.decodeFile() and BitmapFactory.decodeResource(), and I'd like to specify the format the bitmaps are decoded to, such as RGB_565 or RGBA_8888.

Currently, the decoded bitmap format seems to depend on the incoming image. Alternatively, is there a way to convert an existing bitmap to a specific format?

The reason this is important is that when I try to decode the image using jnigraphics, some images return an AndroidBitmapFormat of type ANDROID_BITMAP_FORMAT_NONE, which I assume is useless. Does anyone have more insight into why the format would be none of the known values? When this happens, the built-in image picker correctly displays images that are decoded this way, so I assume there has to be a way to deal with them.

Thanks for your input!

Daniel Schuler
  • 3,130
  • 2
  • 30
  • 28

2 Answers2

23

This might be what you are looking for:

BitmapFactory.Options op = new BitmapFactory.Options();
op.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeFile(path, op);
Mihai
  • 254
  • 2
  • 3
1

When you have bitmap you can call copy method on it specifying BitmapConfig which is basically what you want. http://developer.android.com/reference/android/graphics/Bitmap.html#copy(android.graphics.Bitmap.Config,boolean)

Jarek Potiuk
  • 19,317
  • 2
  • 60
  • 61
  • I was hoping there would be a way to do this during decode, instead of making a copy later. It looks like this is the only way though. – Daniel Schuler Jun 26 '11 at 04:12