Android圖片剪裁庫:uCrop

ForestSandr 8年前發布 | 66K 次閱讀 Android開發 移動開發

Yalantis的新作品,圖片剪裁庫,支持圖片旋轉。

使用說明:

 

在項目中引入庫:

compile 'com.yalantis:ucrop:1.0.1'

在AndroidManifest.xml中添加UCropActivity:

<activity
    android:name="com.yalantis.ucrop.UCropActivity"
    android:screenOrientation="portrait"/>

uCrop的配置是使用的builder模式:

UCrop.of(sourceUri, destinationUri)
    .withAspectRatio(16, 9)
    .withMaxResultSize(maxWidth, maxHeight)
    .start(context);

重寫onActivityResult方法并處理裁剪的結果:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
        final Uri resultUri = UCrop.getOutput(data);
    } else if (resultCode == UCrop.RESULT_ERROR) {
        final Throwable cropError = UCrop.getError(data);
    }
}

 

 

項目地址: https://github.com/Yalantis/uCrop

 本文由用戶 ForestSandr 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!