How to attach EXIF metadata to a serialized Bitmap in Android? -
in android, when decoding bitmap photo on phone, exif data in original gets lost. sending bitmap server via socket , re-attach missing exif data data being sent.
i have code loads bitmap object mediastore , compresses byte array in preparation send on socket:
bitmap bitmap = ... bytearrayoutputstream stream = new bytearrayoutputstream(bitmap); bitmap.compress(compressformat.jpeg, 70, stream); byte[] input = stream.tobytearray();
i want use exifinterface @ exif metadata in original jpeg on sd card , somehow add outgoing byte array in way i'd able extract jpeg correct exif on server side (hopefully without doing on server). far, managed use exifinterface read exif data:
string path = ... //bitmap file path exifinterface exif = new exifinterface(path); ... = exif.getattribute(...)
edit: optimally, i'd find solution uses no libraries. if indices of byte array of original jpeg contain exif , prepend/append these bytes byte array produced bitmap.compress(...)
best.
thanks @nick campion , sanselan.
working code:
bytearrayoutputstream bos = new bytearrayoutputstream(); bitmap.compress(compressformat.jpeg, 100, bos); //bitmap object image byte[] data = bos.tobytearray(); tiffoutputset outputset = null; iimagemetadata metadata = sanselan.getmetadata(new file(filepath)); // filepath path 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 byte array, contains exif information! }
Comments
Post a Comment