Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. Bitmap bitmap = ...
  2. ByteArrayOutputStream stream = new ByteArrayOutputStream(bitmap);
  3. bitmap.compress(CompressFormat.JPEG, 70, stream);
  4. byte[] input = stream.toByteArray();
  5.  
  6. String path = ... //bitmap file path
  7. ExifInterface exif = new ExifInterface(path);
  8. ... = exif.getAttribute(...)
  9.  
  10. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  11. bitmap.compress(CompressFormat.JPEG, 100, bos); //Bitmap object is your image
  12. byte[] data = bos.toByteArray();
  13.  
  14. TiffOutputSet outputSet = null;
  15.  
  16. IImageMetadata metadata = Sanselan.getMetadata(new File(filepath)); // filepath is the path to your image file stored in SD card (which contains exif info)
  17. JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
  18. if (null != jpegMetadata)
  19. {
  20. TiffImageMetadata exif = jpegMetadata.getExif();
  21. if (null != exif)
  22. {
  23. outputSet = exif.getOutputSet();
  24. }
  25. }
  26. if (null != outputSet)
  27. {
  28. bos.flush();
  29. bos.close();
  30. bos = new ByteArrayOutputStream();
  31. ExifRewriter ER = new ExifRewriter();
  32. ER.updateExifMetadataLossless(data, bos, outputSet);
  33. data = bos.toByteArray(); //Update you Byte array, Now it contains exif information!
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement