4

I am trying to fetch a thumbnail image from DNG RAW image file and show it in android. I have successfully read all the required tags and get the values to form an image. But I haven't worked with image before so facing problem with bitmap creation. By reading the raw image tags I have got the below values:

image width = 320

image height = 216

compression = 1 (1=uncompressed)

sample Per Pixel = 3

bit Per Sample = 8

image start offset = 7044

color Interpretation = 2 (2=ARGB_8888)

to fetch the image data my code is:

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();

from the above code I am getting a byte arry of uncompressed image data. But I am convering it into a bitmap, getting bitmap as null.

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

So, how can I create a bitmap properly? Advance thanks for any help.

0 Answers0