uCrop 介绍
ucrop 是Yalantis 组织开源的图片裁剪库, 支持缩放, 旋转图片, 支持各种比例的裁剪框,
非常强大的一个图片裁剪库。
使用
1. 添加包.
compile 'com.yalantis:ucrop:1.3.+'
2. 注册 ucropActivity 在 AndroidManifest.xml中
<activity android:name="com.yalantis.ucrop.ucropActivity" android:screenorientation="portrait" android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
3. 代码设置
ucrop.of(sourceUri, destinationUri) .withAspectRatio(16, 9) .withMaxResultSize(maxWidth, maxHeight) .start(context);
4. 实现继承的方法
@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); } }
uCrop 官网
https://yalantis.com/blog/introducing-ucrop-our-own-image-cropping-library-for-android/