Android-CropView

Introduction: 超简单实现图片裁切功能
More: Author   ReportBugs   
Tags:
CropView 图片裁切-图片裁切-CropView-


介绍

android image cropping library. Support from camera, gallery, image rotate.

Android 的图像裁剪库。支持从相机,图库选择图片,裁切时图像旋转。

使用

  • 导入 lib-cropview 并在 AndroidManifest.xml 中添加 Activity

    <activity android:name="com.jeanboy.cropview.cropper.CropActivity"
              android:theme="@style/AppTheme.NoActionBar"/>
    
  • 实现 CropperHandler 并实现方法

      @Override
      public Activity getActivity() {
          return this;
      }
    
      @Override
      public CropperParams getParams() {
          //配置裁切框比例
          return new CropperParams(1, 1);
          //不约束裁切比例
          // return new CropperParams(0, 0);
      }
    
      @Override
      public void onCropped(Uri uri) {
          Log.d("=====onCropped======", "======裁切成功=======" + uri);
      }
    
      @Override
      public void onCropCancel() {
          Log.d("=====onCropCancel====", "======裁切取消=====");
      }
    
      @Override
      public void onCropFailed(String msg) {
          Log.d("=====onCropFailed===", "=======裁切失败======" + msg);
      }
    
  • 初始化 CropperManager

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        CropperManager.getInstance().build(this);
    }


     @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        CropperManager.getInstance().handlerResult(requestCode, resultCode, data);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        CropperManager.getInstance().destroy();
    }
  • 调用操作
    CropperManager.getInstance().pickFromCamera();//拍照裁切
    CropperManager.getInstance().pickFromGallery();//图库选择裁切
    

    注意事项

    CropActivity 不需要 ActionBar
    <style name="AppTheme.NoActionBar" parent="AppTheme">
      <!-- 关闭 ActionBar -->
      <item name="windowActionBar">false</item>
      <!-- 隐藏 title -->
      <item name="windowNoTitle">true</item>
    </style>
    

Demo

演示

感谢

关于我

如果对你有帮助,请 star 一下,然后 follow 我,给我增加一下分享动力,谢谢!

如果你有什么疑问或者问题,可以提交 issue 和 request,发邮件给我 jeanboy@foxmail.com 。

或者加入下面的 QQ 群来一起学习交流。

Android 技术进阶:386463747

License

Copyright 2015 jeanboy

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Apps
About Me
Google+: Trinea trinea
GitHub: Trinea