This is an automated email from the ASF dual-hosted git repository.

normanbreau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-camera.git


The following commit(s) were added to refs/heads/master by this push:
     new a672c31  fix(android): Return data uris as an URI (#910)
a672c31 is described below

commit a672c31efb3d882eac1d47c7b2f8ae1164ca6175
Author: Norman Breau <nor...@breautek.com>
AuthorDate: Sat Oct 26 00:58:00 2024 -0300

    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 5b95d40..b00b005 100644
--- a/src/android/CameraLauncher.java
+++ b/src/android/CameraLauncher.java
@@ -1286,23 +1286,25 @@ public class CameraLauncher extends CordovaPlugin 
implements MediaScannerConnect
      * @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;
     }
 
     /**


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to