From a672c31efb3d882eac1d47c7b2f8ae1164ca6175 Mon Sep 17 00:00:00 2001 From: Norman Breau Date: Sat, 26 Oct 2024 00:58:00 -0300 Subject: [PATCH] fix(android): Return data uris as an URI (#910) --- src/android/CameraLauncher.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index 5b95d400e..b00b00539 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -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; } /**