如何附加EXIF元数据在Android的序列化的Bitmap? [英] How to attach EXIF metadata to a serialized Bitmap in Android?
问题描述
在Android的,解码时从手机上的照片的位图,在原有的EXIF数据丢失。我通过一个套接字发送此位图到我的服务器,并希望丢失的EXIF数据重新连接到所发送的数据。
In Android, when decoding a Bitmap from a photo on the phone, the EXIF data in the original gets lost. I am sending this Bitmap to my server via a socket and would like to re-attach the missing EXIF data to the data being sent.
我有一些code加载从MediaStore Bitmap对象和COM $ P $它psses在preparation字节数组它通过套接字发送:
I have some code that loads a Bitmap object from the MediaStore and compresses it to a byte array in preparation to send it over a socket:
Bitmap bitmap = ...
ByteArrayOutputStream stream = new ByteArrayOutputStream(bitmap);
bitmap.compress(CompressFormat.JPEG, 70, stream);
byte[] input = stream.toByteArray();
我想使用ExifInterface得到的EXIF元数据在原来的JPEG在SD卡上,并以某种方式添加到的方式传出的字节数组,我会能够提取一个JPEG与所有正确的EXIF在服务器端(希望无需在服务器上这样做)。到目前为止,我设法用ExifInterface读取所有EXIF数据:
I want to use the ExifInterface to get at the EXIF metadata in the original jpeg on the SD card and somehow add that to the outgoing byte array in a way that I'd be able to extract a jpeg with all the correct EXIF on the server side (hopefully without doing this on the server). So far, I managed to use the ExifInterface to read all EXIF data:
String path = ... //bitmap file path
ExifInterface exif = new ExifInterface(path);
... = exif.getAttribute(...)
编辑:理想情况下,我想找到不使用图书馆的解决方案。如果我能得到包含EXIF和prePEND原始的JPEG的字节数组的索引/追加这些字节由 bitmap.com preSS(产生的字节数组.. 。)
这将是最好的。
推荐答案
由于 @Nick坎皮恩和< A HREF =http://commons.apache.org/sanselan/相对=nofollow> Sanselan 。
工作code:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, bos); //Bitmap object is your image
byte[] data = bos.toByteArray();
TiffOutputSet outputSet = null;
IImageMetadata metadata = Sanselan.getMetadata(new File(filepath)); // filepath is the path to your image file stored in SD card (which contains exif info)
JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
if (null != jpegMetadata)
{
TiffImageMetadata exif = jpegMetadata.getExif();
if (null != exif)
{
outputSet = exif.getOutputSet();
}
}
if (null != outputSet)
{
bos.flush();
bos.close();
bos = new ByteArrayOutputStream();
ExifRewriter ER = new ExifRewriter();
ER.updateExifMetadataLossless(data, bos, outputSet);
data = bos.toByteArray(); //Update you Byte array, Now it contains exif information!
}
这篇关于如何附加EXIF元数据在Android的序列化的Bitmap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!