0

I'm not able to retrieve image after cropping, here is my code everything is correct ??? I'm just looking to crop an image from gallery and then upload it to an ImageView

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", 1);
 intent.putExtra("aspectY", 1);
 intent.putExtra("outputX", 400);
 intent.putExtra("outputY", 400);
 intent.putExtra("scale", true);
 intent.putExtra("scaleUpIfNeeded", true);
 intent.putExtra(MediaStore.EXTRA_OUTPUT, "image");
 intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());

 try {
     intent.putExtra("return-data", false);
    startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY);
 }

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == PICK_FROM_GALLERY) {
            Bundle extras2 = data.getExtras();
            if (extras2 != null) {
                photo = extras2.getParcelable("image");
                attachimage.setImageBitmap(photo);
            }
         }

         if (requestCode == PICK_FROM_CAMERA) {
            Bundle extras = data.getExtras();
            if (extras != null) {
                photo = extras.getParcelable("data");
                attachimage.setImageBitmap(photo);
            }
        }
    }
}
Nadador Base
  • 99
  • 10

1 Answers1

0
intent.putExtra("return-data", false);

You don't recieve data from your activity cause of this.

EDIT (in spite of comment): Then you are doing it wrong, e.g. why read data from bundle when you've requested other output? Take a look at this question & answer: Crop an Image by passing the image file path in Android

Community
  • 1
  • 1
Mikhail Krutov
  • 670
  • 1
  • 5
  • 29