Android takes photos via mobile phone or selects pictures from local album to set avatar

Social apps such as wechat, QQ and microblog usually have the function of setting avatars. There are usually two ways to set avatars:

1. Let users select the existing images in the picture library such as local album and cut them as avatars.

2. Let the user start the camera of the mobile phone to take photos, cut the photos after taking them, and then take them as avatars.

I will now write a simple and complete code example to illustrate how to implement the above two avatar setting functions in Android.

Mainactivity.java file:

The layout file has three components: the ImageView where the avatar is placed and two buttons. One button triggers the operation time of selecting the picture from the local album as the avatar; Another button triggers the mobile phone to take photos as avatars.

activity_ main.xml:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>