zoukankan      html  css  js  c++  java
  • 第三方开源--Android Image Cropper--图片裁剪

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

    首先

    1. 在android studio中导入这个包
    compile 'com.theartofdev.edmodo:android-image-cropper:2.4.+'

    Add permissions to manifest

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    有两种使用方式:

    第一种: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原作者

  • 相关阅读:
    MVC在View中页面跳转
    javaEE之------ApectJ的切面技术===标签
    Service的生命周期
    Codeforces Round #253 (Div. 2)
    hdu 3183 A Magic Lamp(给一个n位的数,从中删去m个数字,使得剩下的数字组成的数最小(顺序不能变),然后输出)
    【转】理解红黑树
    概要设计注意事项
    C++ 初始化与赋值
    UE 的使用
    内存泄漏
  • 原文地址:https://www.cnblogs.com/woaixingxing/p/7218538.html
Copyright © 2011-2022 走看看