I am taking images using the camera on an Android phone. After the image is taken, I pass the full image as a uri to the crop intent (com.android.camera.action.CROP). However, when the crop intent comes back, it returns in the parcelable at thumbnail size. I have tried to save the image from the camera in a file and send the uri of the file instead but it doesn't open the image in the crop intent. How can I get the full size image that I cropped in the crop intent from the parcel it sends back? Here is some of the code I am using:
public void onActivityResult(int requestCode, int resultCode,
Intent intent) {
if (resultCode != Activity.RESULT_CANCELED) {
Uri uri = null;
switch (requestCode) {
case FILE_SELECT_CODE:
if (intent.getData() != null) {
uri = intent.getData();
cropSelectedPicture(uri);
}
break;
case PICTURE_SELECT_CODE:
uri = intent.getData();
if (uri == null) {
Bundle bundle = intent.getExtras();
Bitmap photo = null;
if (bundle != null) {
photo = bundle.getParcelable("data");
}
finishChangeProfilePicture(photo);
} else {
cropSelectedPicture(uri);
}
break;
case FILE_CROP_CODE:
Bundle extras = intent.getExtras();
Bitmap thePic = extras.getParcelable("data");
uri = extras.getParcelable("uri");
finishChangeProfilePicture(thePic);
break;
}
}
super.onActivityResult(requestCode, resultCode, intent);
}
public void showCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("crop", "true");
intent.putExtra("outputX", pictureWidth);
intent.putExtra("outputY", pictureHeight);
intent.putExtra("aspectX", pictureWidth);
intent.putExtra("aspectY", pictureHeight);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
try {
cordova.startActivityForResult(
this, Intent.createChooser(intent, "Take Picture"),
PICTURE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(context, "Please install a Camera application.",
Toast.LENGTH_SHORT).show();
}
}
public void cropSelectedPicture(Uri uri) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("outputX", pictureWidth);
intent.putExtra("outputY", pictureHeight);
intent.putExtra("aspectX", pictureWidth);
intent.putExtra("aspectY", pictureHeight);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
if (activities.size() > 0) {
for (int i = 0; i < activities.size(); i++) {
String label = (String) activities.get(i).loadLabel(packageManager);
if (label.equals("Crop picture")) {
ActivityInfo activity = activities.get(i).activityInfo;
ComponentName name = new ComponentName (activity.applicationInfo.packageName,
activity.name);
intent.setComponent(name);
}
}
}
try {
cordova.startActivityForResult(this, intent, FILE_CROP_CODE);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(context, "Please install a Cropping program", Toast.LENGTH_SHORT).show();
}
}
CROP
Intent
: commonsware.com/blog/2013/01/23/… – CommonsWare