android裁剪图片功能,Android实现拍照、选择图片并裁剪图片功能

一、 实现拍照、选择图片并裁剪图片效果

按照之前博客的风格,首先看下实现效果。

90fa31c3a3bf0da71508668a53b98a9f.gif

4faa920d79537a8540795c70de5330ae.gif

二、 uCrop项目应用

想起之前看到的Yalantis/uCrop效果比较绚,但是研究源码之后发现在定制界面方面还是有一点的限制,于是在它的基础上做了修改Android-Crop,把定制界面独立出来,让用户去自由设置。下图为使用Android-Crop实现的模仿微信选择图片并裁剪Demo。

f1cae529d138bbdfce8e91deac9f07f0.gif

三、 实现思路

比较简单的选择设备图片裁剪,并将裁剪后的图片保存到指定路径;

调用系统拍照,将拍照图片保存在SD卡,然后裁剪图片并将裁剪后的图片保存在指定路径。

流程图如下所示:

3614ea82660c018d9a8032b8f2a6d991.png

四、 选择框实现

这里通过PopupWindow来实现,当然也可以根据需求采用其他方式实现。实现效果如下图所示:

551d00040889027dd249f4ef4f8e41e0.gif

1. XML布局

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:gravity="center_horizontal"

android:orientation="vertical">

android:id="@+id/pop_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:background="#444"

android:gravity="center_horizontal"

android:orientation="vertical">

android:id="@+id/picture_selector_take_photo_btn"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="10dip"

android:layout_marginRight="10dip"

android:layout_marginTop="10dp"

android:background="#4d69ff"

android:padding="10dp"

android:text="拍照"

android:textColor="#CEC9E7"

android:textSize="18sp"

android:textStyle="bold" />

android:id="@+id/picture_selector_pick_picture_btn"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="10dip"

android:layout_marginRight="10dip"

android:layout_marginTop="5dp"

android:background="#4d69ff"

android:padding="10dp"

android:text="从相册选择"

android:textColor="#CEC9E7"

android:textSize="18sp"

android:textStyle="bold" />

android:id="@+id/picture_selector_cancel_btn"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="15dip"

android:layout_marginLeft="10dip"

android:layout_marginRight="10dip"

android:layout_marginTop="20dp"

android:background="@android:color/white"

android:padding="10dp"

android:text="取消"

android:textColor="#373447"

android:textSize="18sp"

android:textStyle="bold" />

2. 代码编写

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值