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.
我正在对BitmapFactory.decodeFile()和BitmapFactory.decodeResource()进行多次调用,我想指定解码位图的格式,比如RGB_565或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.
这一点很重要的原因是,当我尝试使用jnigraphics解码图像时,有些图像返回android_bitmapformat类型为ANDROID_BITMAP_FORMAT_NONE,我认为这是无用的。有没有人能更深入地理解为什么格式没有已知的值?当发生这种情况时,内置的图像选择器将正确显示以这种方式解码的图像,因此我假设必须有一种方法来处理它们。
Thanks for your input!
谢谢你的输入!
2 个解决方案
#1
22
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);
#2
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)
当你有位图时你可以调用它的复制方法指定位图配置,这基本上就是你想要的。http://developer.android.com/reference/android/graphics/Bitmap.html副本(android.graphics.Bitmap.Config、布尔)
#1
22
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);
#2
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)
当你有位图时你可以调用它的复制方法指定位图配置,这基本上就是你想要的。http://developer.android.com/reference/android/graphics/Bitmap.html副本(android.graphics.Bitmap.Config、布尔)