How to save Exif data after bitmap compression in

2019-02-17 18:50发布

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条回答
神经病院院长
2楼-- · 2019-02-17 19:46

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

查看更多
登录 后发表回答