第三方开源--Android Image Cropper--图片裁剪

github下载地址:https://github.com/ArthurHub/Android-Image-Cropper

有两种使用方式:

第一种:Activity用法

1.添加 CropImageActivity 到 AndroidManifest.xml里面:

<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"/>

2.在你要使用裁剪的地方调用:

CropImage.activity(imageUri)
  .setGuidelines(CropImageView.Guidelines.ON)
  .start(this);

3.重写onActivityResult判断得到裁剪的图片uri:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
       CropImage.ActivityResult result = CropImage.getActivityResult(data);
       if (resultCode == RESULT_OK) {
           Uri resultUri = result.getUri();
       } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
           Exception error = result.getError();
       }
   }
}

第二种:View用法

1.增加CropImageView到你的Activity:

<!-- Image Cropper fill the remaining available height -->
<com.theartofdev.edmodo.cropper.CropImageView
  xmlns:custom="http://schemas.android.com/apk/res-auto"
  android:id="@+id/cropImageView"
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_weight="1"/>

2.用到的时候设置地址uri

cropImageView.setImageBitmap(bitmap);
// or
cropImageView.setImageUriAsync(uri);

3.得到裁剪图片:

Bitmap cropped = cropImageView.getCroppedImage();
// or (must subscribe to async event using cropImageView.setOnGetCroppedImageCompleteListener(listener))
cropImageView.getCroppedImageAsync();

详情见github原作者

原文地址:https://www.cnblogs.com/zzw1994/p/5531077.html