mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-04-09 09:33:53 +08:00
fix(android): Return data uris as an URI (#910)
This commit is contained in:
parent
16325102c7
commit
a672c31efb
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user