Android第三方开源图片裁剪截取:cropper

很多app都需要裁剪截取图片作为头像、logo之类,而cropper是github上的一个针对Android平台的、第三方开源图片裁剪截取项目,其项目主页是:https://github.com/edmodo/cropper

cropper项目给出的一个例子以一张蝴蝶图作为目标图片进行裁剪截取,如图:

cropper用法简单,给出一个例子,测试的MainActivity.java:

  1. package zhangphil.demo;
  2.  
  3. import com.edmodo.cropper.CropImageView;
  4.  
  5. import android.app.Activity;
  6. import android.graphics.Bitmap;
  7. import android.os.Bundle;
  8. import android.view.View;
  9.  
  10. public class MainActivity extends Activity {
  11.  
  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.activity_main);
  16.  
  17. final CropImageView cropImageView = (CropImageView) findViewById(R.id.CropImageView);
  18.  
  19. // 当触摸时候才显示网格线
  20. cropImageView.setGuidelines(CropImageView.GUIDELINES_ON_TOUCH);
  21.  
  22. findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
  23.  
  24. @Override
  25. public void onClick(View v) {
  26. // 获取裁剪成的图片
  27. Bitmap croppedImage = cropImageView.getCroppedImage();
  28.  
  29. cropImageView.setImageBitmap(croppedImage);
  30. }
  31. });
  32. }
  33. }

需要的布局文件:

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical"
  6. tools:context="zhangphil.demo.MainActivity" >
  7.  
  8. <com.edmodo.cropper.CropImageView
  9. xmlns:custom="http://schemas.android.com/apk/res-auto"
  10. android:id="@+id/CropImageView"
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:adjustViewBounds="true"
  14. android:src="@drawable/girl" />
  15.  
  16. <Button
  17. android:id="@+id/button"
  18. android:layout_width="wrap_content"
  19. android:layout_height="wrap_content"
  20. android:text="裁剪" >
  21. </Button>
  22.  
  23. </LinearLayout>

附录文章:

1,《Android设置头像,手机拍照或从本地相册选取图片作为头像》链接地址:http://blog.csdn.net/zhangphil/article/details/44829747

Android第三方开源图片裁剪截取:cropper的更多相关文章

  1. Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)

    Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog) Android第三方开源对话消息提示框:SweetAlertDialog(sweet- ...

  2. Android第三方开源SeekBarCompat:音乐类播放器等APP进度条常用

     Android第三方开源SeekBarCompat:音乐类播放器等APP进度条常用 Android平台原生的SeekBar设计简单,然而,比如现在流行的一些音乐播放器的播放进度控制条,如果直接使 ...

  3. Android第三方开源SwitchButton

    Android第三方开源SwitchButton Android SwitchButton是github上的一个第三方开源项目,其项目主页是:https://github.com/kyleduo/Sw ...

  4. Android第三方开源下拉框:NiceSpinner

     Android第三方开源下拉框:NiceSpinner Android原生的下拉框Spinner基本上可以满足Android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于Andro ...

  5. 030 Android 第三方开源下拉框:NiceSpinner的使用+自定义Button样式+shape绘制控件背景图+图片选择器(selector)

    1.NiceSpinner下拉框控件介绍 Android原生的下拉框Spinner基本上可以满足Android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于Android原生提供的下拉框 ...

  6. Android 第三方开源库收集整理(转)

    原文地址:http://blog.csdn.net/caoyouxing/article/details/42418591 Android开源库 自己一直很喜欢Android开发,就如博客签名一样,  ...

  7. 45.Android 第三方开源库收集整理(转)

    原文地址:http://blog.csdn.net/caoyouxing/article/details/42418591 Android开源库 自己一直很喜欢Android开发,就如博客签名一样,  ...

  8. Android 第三方开源下拉框:NiceSpinner

    Android原生的下拉框Spinner基本上可以满足Android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于Android原生提供的下拉框Spinner所提供的设计样式,而改用自定 ...

  9. 【我的Android进阶之旅】如何快速寻找Android第三方开源库在Jcenter上的最新版本

    问题描述 解决方法 先了解compile comsquareupokhttpokhttp240的意义 了解Jcenter和Maven jcenter Maven Central 理解jcenter和M ...

随机推荐

  1. [BZOJ 2199] 奶牛议会

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2199 [算法] 2-SAT [代码] #include<bits/stdc++ ...

  2. YES,IT IS

  3. hibernate中id中的 precision 和 scale 作用

    转自:https://www.cnblogs.com/IT-Monkey/p/4077570.html <hibernate-mapping>     <class name=&qu ...

  4. [Swift通天遁地]四、网络和线程-(4)使用Alamofire实现网络请求

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. [Swift通天遁地]八、媒体与动画-(5)使用开源类库绘制文字、图形、图像、图表、SVG(可缩放矢量图形)

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. [Swift通天遁地]九、拔剑吧-(16)搭建卡片页面:Card Peek/Pop动态切换界面

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. vue-router路由加载两种模式

    路由安装npm install --save vue-router 安装完成后,打开package.json,如果看到这个"vue-router": 版本号, 就代表安装成功了   ...

  8. 观察者模式-C#实现

    定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新. 观察者模式有四个角色:抽象主题.具体主题.抽象观察者.具体观察者. 抽象主题:把所有观察者对象 ...

  9. 【知识总结】线性筛_杜教筛_Min25筛

    首先感谢又强又嘴又可爱脸还筋道的国家集训队(Upd: WC2019 进候选队,CTS2019 不幸 rk6 退队)神仙瓜 ( jumpmelon ) 给我讲解这三种筛法~~ 由于博主的鸽子属性,这篇博 ...

  10. 【洛谷3321_BZOJ3992】[SDOI2015]序列统计(原根_多项式)

    题目: 洛谷3321 分析: 一个转化思路比较神(典型?)的题-- 一个比较显然的\(O(n^3)\)暴力是用\(f[i][j]\)表示选了\(i\)个数,当前积在模\(m\)意义下为\(j\)的方案 ...