-->

How to save Exif data after bitmap compression in

2019-02-17 18:57发布

问题:

After taking a picture with the camera intent, I compress the bitmap to lower the file size. The problem is that after compression, it loses all EXIF data. I have no problem retrieving the original EXIF data, however, how do I add this EXIFF data after compression into the byte array ?

(My guess is to take the byte array and create a bitmap of that, then add the old EXIF data and thereafter add to byte array again, but this is a mobile application and I'm taking a lot of images so I don't want to waste memory)

Here is the code where I compress the bitmap and save to byte array output stream:

myBitmapImage.compress(Bitmap.CompressFormat.JPEG, 75, outputstream);//Losing EXIF data here
byte[] ba = outputstream.toByteArray(); // How to add EXIF data here ?

回答1:

I found a way in which we can save Exif data after bitmap compression hence posting it here if anyone come across this post.

You can use Apache's import for tiff and ExifTagConstants to add EXIF data back to the byte array image:
org.apache.sanselan.formats.tiff.constants.TagInfo org.apache.sanselan.formats.tiff.constants.ExifTagConstants