您的位置:首页 > 移动开发 > Android开发

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

2016-05-26 14:49 1376 查看


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原作者
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: