fix(android): Return data uris as an URI (#910)

This commit is contained in:
Norman Breau 2024-10-26 00:58:00 -03:00 committed by GitHub
parent 16325102c7
commit a672c31efb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1286,23 +1286,25 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
* @param bitmap * @param bitmap
*/ */
public void processPicture(Bitmap bitmap, int encodingType) { public void processPicture(Bitmap bitmap, int encodingType) {
ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream(); ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
CompressFormat compressFormat = getCompressFormatForEncodingType(encodingType); CompressFormat compressFormat = getCompressFormatForEncodingType(encodingType);
try { try {
if (bitmap.compress(compressFormat, mQuality, jpeg_data)) { if (bitmap.compress(compressFormat, mQuality, dataStream)) {
byte[] code = jpeg_data.toByteArray(); 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); byte[] output = Base64.encode(code, Base64.NO_WRAP);
String js_out = new String(output); sb.append(new String(output));
this.callbackContext.success(js_out); this.callbackContext.success(sb.toString());
js_out = null;
output = null; output = null;
code = null; code = null;
} }
} catch (Exception e) { } catch (Exception e) {
this.failPicture("Error compressing image: "+e.getLocalizedMessage()); this.failPicture("Error compressing image: "+e.getLocalizedMessage());
} }
jpeg_data = null;
} }
/** /**