Reputation: 67
This is the code which opens gallery and pick an image to crop it. The change I need is I don't want to open the gallery to pick image. I have already image in my imageview. How can I pass uri of image with intent to use direct crop feature of gallery. what modification I need to do this in below code. Thanks!
Intent intent = new Intent();
// call android default gallery
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// ******** code for crop image
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 150);
I have modified it with
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setData(edtImgUri);
but it is also not working.
Upvotes: 1
Views: 530
Reputation: 11992
You must add the output
and outputFormat
Extra's to the intent. Output should be carfeully chosen, so that it can be written by the system (gallery), and read by your app.
This is working for me :
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
// We should always get back an image that is no larger than these
// dimensions
intent.putExtra("outputX", 128);
intent.putExtra("outputY", 128);
// Scale the image down to 128 x 128
intent.putExtra("scale", true);
intent.putExtra("windowTitle",
profileActivity.getString(R.string.pick_picture));
File tempFile = new File(Environment.getExternalStorageDirectory(),
"/crop_avatar.png");
mSavedUri = Uri.fromFile(tempFile);
intent.putExtra("output", mSavedUri);
intent.putExtra("outputFormat", "PNG");
profileActivity.startActivityForResult(intent, INTENT_PICK_PICTURE);
Upvotes: 1