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!
The BitmapFactory creates a bitmap object with this image and we use the ImageView. setImageBitmap() method to update the ImageView component. 2) From an Input stream. Use BitmapFactory. decodeStream() to convert a BufferedInputStream into a bitmap object.
Config ARGB_8888. Each pixel is stored on 4 bytes. Each channel (RGB and alpha for translucency) is stored with 8 bits of precision (256 possible values.) This configuration is very flexible and offers the best quality.
DecodeStream(Stream)Decode an input stream into a bitmap.
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);
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With