Skip to content

Commit

Permalink
fix(android): Return data uris as an URI
Browse files Browse the repository at this point in the history
  • Loading branch information
breautek committed Oct 26, 2024
1 parent 1632510 commit 3c54c97
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/android/CameraLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -1286,23 +1286,25 @@ private Uri whichContentStore() {
* @param bitmap
*/
public void processPicture(Bitmap bitmap, int encodingType) {
ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
CompressFormat compressFormat = getCompressFormatForEncodingType(encodingType);

try {
if (bitmap.compress(compressFormat, mQuality, jpeg_data)) {
byte[] code = jpeg_data.toByteArray();
if (bitmap.compress(compressFormat, mQuality, dataStream)) {
StringBuilder sb = new StringBuilder()
.append("data:")
.append(encodingType == PNG ? PNG_MIME_TYPE : JPEG_MIME_TYPE)
.append(";base64,");
byte[] code = dataStream.toByteArray();
byte[] output = Base64.encode(code, Base64.NO_WRAP);
String js_out = new String(output);
this.callbackContext.success(js_out);
js_out = null;
sb.append(new String(output));
this.callbackContext.success(sb.toString());
output = null;
code = null;
}
} catch (Exception e) {
this.failPicture("Error compressing image: "+e.getLocalizedMessage());
}
jpeg_data = null;
}

/**
Expand Down

0 comments on commit 3c54c97

Please sign in to comment.