我如何与BitmapFactory.de code *指定位图格式(如RGBA_8888)()?位图、格式、de、BitmapFactory

由网友(笑着说分手)分享简介:我正在做多次打电话给 BitmapFactory.de codeFILE()和 BitmapFactory.de codeResource(),我想指定格式的位图德coded到,如RGB_565或RGBA_8888。I'm making several calls to BitmapFactory.decodeFil...

我正在做多次打电话给 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 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);