From 6cd2b1db61a69bbd371a41927150c338b70b88b7 Mon Sep 17 00:00:00 2001 From: mvan Date: Wed, 8 Nov 2023 11:54:10 +0100 Subject: [PATCH] fix(android): Fixed exif handling when loading picture from gallery --- src/android/CameraLauncher.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index ef730d6..0e76f85 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -778,7 +778,22 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // If sending base64 image back if (destType == DATA_URL) { - this.processPicture(bitmap, this.encodingType); + // To allow keeping the Exif data, we need to save the image to allow ExifInterface add the data + // After that, we load the image and send it as base64 + try { + String modifiedPath = this.outputModifiedBitmap(bitmap, uri, mimeTypeOfGalleryFile); + InputStream fileStream = FileHelper.getInputStreamFromUriString(modifiedPath, cordova); + byte[] file = new byte[fileStream.available()]; + + fileStream.read(file); + + byte[] output = Base64.encode(file, Base64.NO_WRAP); + String js_out = new String(output); + this.callbackContext.success(js_out); + } catch (IOException e) { + e.printStackTrace(); + this.failPicture("Error retrieving image: "+e.getLocalizedMessage()); + } } // If sending filename back