在Android中,从手机上的照片解码位图时,原始的EXIF数据会丢失。我通过套接字将此 Bitmap
发送到我的服务器,并希望重新附加丢失的EXIF数据以发送数据。
我有一些代码,从 MediaStore
中加载一个 Bitmap
对象并将其压缩为字节数组,准备将其通过套接字发送:
Bitmap bitmap = ...
ByteArrayOutputStream stream = new ByteArrayOutputStream(bitmap);
bitmap.compress(CompressFormat.JPEG, 70, stream);
byte[] input = stream.toByteArray();
我想使用ExifInterface
来获取SD卡上原始jpeg文件中的EXIF元数据,并以某种方式将其添加到传出的字节数组中,以便在服务器端能够提取具有所有正确EXIF的jpeg图像(希望不必在服务器上执行此操作)。到目前为止,我成功地使用ExifInterface
读取了所有EXIF数据:
String path = ... //bitmap file path
ExifInterface exif = new ExifInterface(path);
... = exif.getAttribute(...)
编辑:最理想的情况是找到不使用任何库的解决方案。如果我能够获得原始jpeg字节数组中包含EXIF的索引,并将这些字节前缀/后缀到由bitmap.compress(...)
生成的字节数组中,那将是最好的。