gpt4 book ai didi

java - Android 16 位彩色图像到位图

转载 作者:行者123 更新时间:2023-11-30 11:30:22 24 4
gpt4 key购买 nike

我正在尝试从嵌入式相机 (datasheet here) 获取分辨率为 80 x 60 的 16 位彩色图像。我成功地从相机中获取了 9600 (80 * 60 * 16/8) 字节,但是我在显示图像时遇到了问题。我正在使用以下代码将字节数组转换为位图:

bm = Bitmap.createBitmap(80, 60, Bitmap.Config.RGB_565);
bm.copyPixelsFromBuffer(ByteBuffer.wrap(jpegBytes));

jpegBytes 是图像字节数组,长度为 9600 字节。

现在,我得到的图像看起来像这样:

corrupted image

99% 的时间。但是,我可以获得如下所示的未损坏图像:

uncorrupted image

很少。有没有人对为什么会这样有任何建议?非常感谢!

更新:

似乎所有像素都在正确的位置,但它们的 RGB 值混淆了。例如,两张照片之间的白色部分是相同的,因为 RGB 的顺序对于变白无关紧要。然而,很明显颜色混淆了,因为红色椅子在损坏图像中显示为蓝色,而蓝色背包在损坏图像中显示为绿色

最佳答案

使用Config.ARGB_8888作为位图配置

来自 public static final Bitmap.Config RGB_565 的文档:

Each pixel is stored on 2 bytes and only the RGB channels are encoded: red is stored with 5 bits of precision (32 possible values), green is stored with 6 bits of precision (64 possible values) and blue is stored with 5 bits of precision. This configuration can produce slight visual artifacts depending on the configuration of the source. For instance, without dithering, the result might show a greenish tint. To get better results dithering should be applied. This configuration may be useful when using opaque bitmaps that do not require high color fidelity.

关于java - Android 16 位彩色图像到位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17819425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com