如何使用 BitmapFactory.decode*() 指定位图格式(例如 RGBA_8888)?
我多次调用 BitmapFactory.decodeFile()
和 BitmapFactory.decodeResource()
,并且我想指定位图解码为的格式,例如RGB_565 或 RGBA_8888。
目前,解码的位图格式似乎取决于传入的图像。或者,有没有办法将现有位图转换为特定格式?
这很重要的原因是,当我尝试使用jnigraphics
解码图像时,某些图像返回ANDROID_BITMAP_FORMAT_NONE
类型的AndroidBitmapFormat
,我假设是没用的。有谁更深入地了解为什么格式不是已知值?发生这种情况时,内置图像选择器会正确显示以这种方式解码的图像,因此我认为必须有一种方法来处理它们。
感谢您的投入!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能就是您正在寻找的:
This might be what you are looking for:
当你有位图时,你可以调用它的复制方法,指定 BitmapConfig 这基本上就是你想要的。
http://developer.android .com/reference/android/graphics/Bitmap.html#copy(android.graphics.Bitmap.Config,布尔值)
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)