我如何与BitmapFactory.de code *指定位图格式(如RGBA_8888)()? [英] How can I specify the bitmap format (e.g. RGBA_8888) with BitmapFactory.decode*()?
问题描述
我正在做多次打电话给 BitmapFactory.de codeFILE()
和 BitmapFactory.de codeResource()
,我想指定格式的位图德coded到,如RGB_565或RGBA_8888。
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.
目前,去codeD位图格式似乎取决于输入的图像上。另外,有没有办法到现有的位图转换为特定的格式?
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?
的原因,这是非常重要的是,当我试图去$ C C使用 jnigraphics
,一些图像返回到图像的 AndroidBitmapFormat $ code型>
ANDROID_BITMAP_FORMAT_NONE
,我以为是没用的。有没有人有更深入地了解为什么格式是没有任何已知的价值?发生这种情况时,内置的影像选择器可正确显示被取消codeD这样的图像,所以我想必须有一个方法来处理这些问题。
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.
感谢您的输入!
推荐答案
这可能是你在找什么:
BitmapFactory.Options op = new BitmapFactory.Options();
op.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeFile(path, op);
这篇关于我如何与BitmapFactory.de code *指定位图格式(如RGBA_8888)()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!