Android实现从本地图库/相机拍照后裁剪图片并设置头像

2019-12-10 19:02:46王冬梅

玩qq或者是微信的盆友都知道,这些聊天工具里都要设置头像,一般情况下大家的解决办法是从本地图库选择图片或是从相机拍照,然后根据自己的喜爱截取图片。上述过程已经实现好了,最后一步我加上了把截取好的图片在保存到本地的操作,来保存头像。为了大家需要,下面ASPKU小编把完整的代码贴出来供大家参考。

先给大家展示效果图:

Android实现从本地图库/相机拍照后裁剪图片并设置头像Android实现从本地图库/相机拍照后裁剪图片并设置头像 Android实现从本地图库/相机拍照后裁剪图片并设置头像Android实现从本地图库/相机拍照后裁剪图片并设置头像

代码部分:

布局代码(其实就是两个按钮和一个ImageView来显示头像)

<LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/buttonLocal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="本地相册选取头像" />
<Button
android:id="@+id/buttonCamera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手机拍照选取头像" />
</LinearLayout>