Skip to content

Commit a672c31

Browse files
authored
fix(android): Return data uris as an URI (#910)
1 parent 1632510 commit a672c31

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/android/CameraLauncher.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,23 +1286,25 @@ private Uri whichContentStore() {
12861286
* @param bitmap
12871287
*/
12881288
public void processPicture(Bitmap bitmap, int encodingType) {
1289-
ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
1289+
ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
12901290
CompressFormat compressFormat = getCompressFormatForEncodingType(encodingType);
12911291

12921292
try {
1293-
if (bitmap.compress(compressFormat, mQuality, jpeg_data)) {
1294-
byte[] code = jpeg_data.toByteArray();
1293+
if (bitmap.compress(compressFormat, mQuality, dataStream)) {
1294+
StringBuilder sb = new StringBuilder()
1295+
.append("data:")
1296+
.append(encodingType == PNG ? PNG_MIME_TYPE : JPEG_MIME_TYPE)
1297+
.append(";base64,");
1298+
byte[] code = dataStream.toByteArray();
12951299
byte[] output = Base64.encode(code, Base64.NO_WRAP);
1296-
String js_out = new String(output);
1297-
this.callbackContext.success(js_out);
1298-
js_out = null;
1300+
sb.append(new String(output));
1301+
this.callbackContext.success(sb.toString());
12991302
output = null;
13001303
code = null;
13011304
}
13021305
} catch (Exception e) {
13031306
this.failPicture("Error compressing image: "+e.getLocalizedMessage());
13041307
}
1305-
jpeg_data = null;
13061308
}
13071309

13081310
/**

0 commit comments

Comments
 (0)