6

I have a picture I want to post as imageButton but before posting it I have a cropper:

private void CropImage() {

    try {
        CropIntent = new Intent("com.android.camera.action.CROP");
        CropIntent.setDataAndType(uri, "image/*");

        CropIntent.putExtra("crop", "true");
        CropIntent.putExtra("outputX", 180);
        CropIntent.putExtra("outputY", 180);
        CropIntent.putExtra("aspectX", 3);
        CropIntent.putExtra("aspectY", 4);
        CropIntent.putExtra("scaleUpIfNeeded", true);
        CropIntent.putExtra("return-data", true);

        startActivityForResult(CropIntent , 1);
    }
    catch (ActivityNotFoundException ex){

    }

}

And when I select a picture from gallery or take a picture with my camera it shows a toast Editing is not supported for this Image, and I'm not sure what's really causing this.

This is my GalleryOpen() and CameraOpen():

private void GalleryOpen() {
    GalleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(Intent.createChooser(GalleryIntent, "Select Images From Gallery"), 2);
}

private void CameraOpen() {
    CamIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    file = new File(Environment.getExternalStorageDirectory(),
            "file"+String.valueOf(System.currentTimeMillis())+ ".jpg");
    uri = FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID + ".provider", file);
    CamIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    CamIntent.putExtra("return-data", true);
    CamIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivityForResult(CamIntent, 0);

}

And my OnActivityResult:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 0 && resultCode == RESULT_OK)
        CropImage();
    else if(requestCode == 2) {
        if (data != null) {
            uri = data.getData();
            CropImage();
        }
    }
    else if(requestCode == 1) {
        if(data != null){
            Bundle bundle = data.getExtras();
            Bitmap bitmap = bundle.getParcelable("data");
            imageHolder.setImageBitmap(bitmap);
        }
    }

}
Bulat
  • 720
  • 7
  • 15
Kristofer
  • 87
  • 1
  • 8
  • 1
    [Android does not have a crop intent](https://commonsware.com/blog/2013/01/23/no-android-does-not-have-crop-intent.html) and https://stackoverflow.com/q/40109668/295004 and https://stackoverflow.com/q/41337479/295004 – Morrison Chang Mar 18 '18 at 02:15
  • Did you find a solution? – Ton Feb 04 '21 at 20:41
  • @Ton: this link might be relevant: https://stackoverflow.com/questions/52110987 – paulsm4 Feb 05 '21 at 03:57

0 Answers0