Android-Image-Cropper图片裁剪库试用

刘野
2023-12-01

Android-Image-Cropper图片裁剪库试用

Android-Image-Cropper试用
具体用法参考官方库wiki or demo

  1. build.gradle

    implementation'com.theartofdev.edmodo:android-image-cropper:2.8.0'
    
  2. AndroidManifest.xml

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    
    <activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
        android:theme="@style/Base.Theme.AppCompat"/>
    
  3. Activity/ Fragment

    CropImage.activity()
                        .setGuidelines(CropImageView.Guidelines.ON)
                        .setAspectRatio(1, 1)
                        .setFixAspectRatio(true)
                        .setCropShape(CropImageView.CropShape.OVAL)
                        .start(MainActivity.this);
    
    @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();
            }
        }
    }
    
  4. proguard-rules.pro

     -keep class androidx.appcompat.widget.** { *; }   
    
 类似资料: