How to Crop the image in android marshmallow by us

2019-09-14 10:17发布

In my application requirement is select the image from gallery and then crop the selected image and set to the imageview. Below is my sample code for cropping the image.

//call the standard crop action intent (the user device may not support it)
    Intent cropIntent = new Intent("com.android.camera.action.CROP");
    cropIntent.setClassName("com.android.camera", "com.android.camera.CropImage");
    //indicate image type and Uri
    cropIntent.setDataAndType(mImageCaptureUri, "image/*");
    //set crop properties
    cropIntent.putExtra("crop", "true");
    //indicate aspect of desired crop
    cropIntent.putExtra("aspectX", 1);
    cropIntent.putExtra("aspectY", 1);
    //indicate output X and Y
    cropIntent.putExtra("outputX", 256);
    cropIntent.putExtra("outputY", 256);
    //retrieve data on return
    cropIntent.putExtra("return-data", true);
    cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
    cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    //start the activity - we handle returning in onActivityResult
   startActivityForResult(cropIntent, PIC_CROP);

Above code is works fine in below android marshmallow devises but android marsh mallow it is crashing.How to solve the issue?

1条回答
老娘就宠你
2楼-- · 2019-09-14 10:42

The easiest way to implement camera and gallery with cropping is to use library.in market there are so many third party library are available but none of them work for all devices. There is one library is available which is stable across the deferent and several companies devices. https://github.com/biokys/cropimage use this demo. This is very old library but it is stable across the all different devices.

查看更多
登录 后发表回答