mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-02-22 13:12:50 +08:00
Pass uri to crop instead of pulling the low resolution image out of the intent return (close #43)
This commit is contained in:
parent
03fade661e
commit
8b8db828f6
@ -314,8 +314,10 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
cropIntent.putExtra("aspectX", 1);
|
cropIntent.putExtra("aspectX", 1);
|
||||||
cropIntent.putExtra("aspectY", 1);
|
cropIntent.putExtra("aspectY", 1);
|
||||||
}
|
}
|
||||||
// retrieve data on return
|
// create new file handle to get full resolution crop
|
||||||
cropIntent.putExtra("return-data", true);
|
croppedUri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"));
|
||||||
|
cropIntent.putExtra("output", croppedUri);
|
||||||
|
|
||||||
// start the activity - we handle returning in onActivityResult
|
// start the activity - we handle returning in onActivityResult
|
||||||
|
|
||||||
if (this.cordova != null) {
|
if (this.cordova != null) {
|
||||||
@ -584,36 +586,11 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
|
|||||||
// if camera crop
|
// if camera crop
|
||||||
if (requestCode == CROP_CAMERA) {
|
if (requestCode == CROP_CAMERA) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
// // get the returned data
|
|
||||||
Bundle extras = intent.getExtras();
|
|
||||||
// get the cropped bitmap
|
|
||||||
Bitmap thePic = extras.getParcelable("data");
|
|
||||||
if (thePic == null) {
|
|
||||||
this.failPicture("Crop returned no data.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now save the bitmap to a file
|
|
||||||
OutputStream fOut = null;
|
|
||||||
File temp_file = new File(getTempDirectoryPath(),
|
|
||||||
System.currentTimeMillis() + ".jpg");
|
|
||||||
try {
|
|
||||||
temp_file.createNewFile();
|
|
||||||
fOut = new FileOutputStream(temp_file);
|
|
||||||
thePic.compress(Bitmap.CompressFormat.JPEG, this.mQuality,
|
|
||||||
fOut);
|
|
||||||
fOut.flush();
|
|
||||||
fOut.close();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// // Send Uri back to JavaScript for viewing image
|
// // Send Uri back to JavaScript for viewing image
|
||||||
this.callbackContext
|
this.callbackContext
|
||||||
.success(Uri.fromFile(temp_file).toString());
|
.success(croppedUri.toString());
|
||||||
|
croppedUri = null;
|
||||||
|
|
||||||
}// If cancelled
|
}// If cancelled
|
||||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
this.failPicture("Camera cancelled.");
|
this.failPicture("Camera cancelled.");
|
||||||
|
Loading…
Reference in New Issue
Block a user