4

我正在尝试从 DNG RAW 图像文件中获取缩略图并在 android 中显示它。我已成功读取所有必需的标签并获取形成图像的值。但我之前没有使用过图像,因此面临位图创建问题。通过阅读原始图像标签,我得到了以下值:

图像宽度 = 320

图像高度 = 216

压缩 = 1(1=未压缩)

每像素样本 = 3

每个样本位 = 8

图像起始偏移量 = 7044

颜色解释 = 2 (2=ARGB_8888)

获取图像数据我的代码是:

int uBitsPerPixel = samplePerPixel * bitPerSample;
int lengthOfBitmap = imageLength * imageWidth * uBitsPerPixel/8;//size of image data
InputStream fis = new FileInputStream(file);
byte[] img = new byte[lengthOfBitmap];
fis.skip(startOffset);//image data starting position
fis.read(img, 0, lengthOfBitmap);
fis.close();

从上面的代码中,我得到了一个字节数组的未压缩图像数据。但我将它转换为位图,将位图设为空。

BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeStream(inputStream, null, bmpFactoryOptions);

那么,如何正确创建位图?提前感谢您的帮助。

4

0 回答 0