Android中位图压缩后如何保存Exif数据 [英] How to save Exif data after bitmap compression in Android
问题描述
用相机意图拍照后,我压缩位图以减小文件大小.问题在于压缩后,它将丢失所有EXIF数据.我可以毫无问题地检索原始EXIF数据,但是,在压缩到字节数组后如何添加此EXIFF数据呢?
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 ?
(我的猜测是获取字节数组并为其创建一个位图,然后添加旧的EXIF数据,然后再次添加至字节数组,但这是移动应用程序,我要拍摄很多图像,所以我不想浪费内存)
(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 ?
推荐答案
我找到了一种方法,可以在位图压缩后保存Exif数据,因此如果有人遇到此帖子,可以将其发布到此处.
I found a way in which we can save Exif data after bitmap compression hence posting it here if anyone come across this post.
您可以使用Apache的tiff和ExifTagConstants导入将EXIF数据添加回字节数组图像:
org.apache.sanselan.formats.tiff.constants.TagInfo
org.apache.sanselan.formats.tiff.constants.ExifTagConstants
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
这篇关于Android中位图压缩后如何保存Exif数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!