Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): Fixed exif handling when loading picture from gallery #868

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/android/CameraLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,30 @@ private void processResultFromGallery(int destType, Intent intent) {

// 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);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();

int nRead;
byte[] data = new byte[512];
mariusvn marked this conversation as resolved.
Show resolved Hide resolved

while ((nRead = fileStream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}

buffer.flush();
byte[] file = buffer.toByteArray();

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
Expand Down
Loading