【问题标题】:BitmapFactory null issue in androidandroid中的BitmapFactory null问题
【发布时间】:2011-12-03 02:06:39
【问题描述】:

我正在尝试使用 bitmapfactory 创建位图类。我得到 YUV 格式的相机预览图像并手动解码为灰度图像。当我尝试通过 BitmapFactory 创建位图对象时,它返回 null。

        try {
            for (int y = 0; y < frameHeight; y++){
                for (int x = 0; x < frameWidth; x++){

                    byte grey = YUVData[y * frameWidth + x];
                    convertedData[y * stride + 3 * x] = grey;
                    convertedData[y * stride + 3 * x + 1] = grey;
                    convertedData[y * stride + 3 * x + 2] = grey;

                }
            }

            Bitmap bitmap =(Bitmap) BitmapFactory.decodeByteArray(convertedData, 0, convertedData.length);

【问题讨论】:

标签: java android image-processing bitmap yuv


【解决方案1】:

BitmapFactory 用于从使用 JPEG 或 PNG 编码的图像文件创建图像。如果您只是将原始数据扔给它,则该函数不知道您使用的是什么编码。 RGB?优威? 24 位? 32 位?

AFAIK 没有从 YUV 数据创建图像的本地方法,您至少必须先将其转换为 RGB。这是一个证明它的答案:Getting frames from Video Image in Android

当然,你可以使用NDK创建一个原生的转换函数,这样会快很多。或者您可以扫描文档以查找 YUV 转换器,但我在快速扫描中发现的唯一内容是 YuvImage,它只允许您将其转换为 JPEG 流。

【讨论】:

  • 谢谢,这有助于理解我不能那样做
猜你喜欢
  • 2012-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-23
  • 1970-01-01
  • 2016-10-31
相关资源
最近更新 更多