In Android, set user avatar instances by accessing local photo albums or cameras

At present, almost all apps need to set avatars when users register, which can be roughly divided into three cases:

(1) Get the pictures of the local album and cut them as avatars.

(2) Start the mobile camera, take pictures now, and then cut them as avatars.

(3) Add some self-contained avatar resources to the app for users to choose (not humanized and rarely used at present).

This time, we will briefly introduce how to set avatars by obtaining local photo albums and camera shooting. The implementation idea is as follows:

(1) Use the startactivityforresult method to pass the intent calling the system photo album and the intent calling the camera to take pictures respectively for selection

(2) Call the built-in image clipping in Android system to realize image clipping and obtain data in onactivityresult method.

The effects of this demonstration are as follows (avatars obtained from local album and camera respectively):

@H_ 404_ 19@

The simple layout file will not be repeated here. This experiment uses implicit intent to call the camera and local album. It can still be called without adding permission to the configuration list.

The Java implementation code is as follows:

It should be noted here that when cutting images, the length and width should not be set too large, otherwise it will exceed the cache size limit of the binder mechanism (affected by the mobile phone configuration). Report transactiontoolargeexception, which has been marked in detail in the code. Please pay attention to it when implementing.

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
分享
二维码
< <上一篇
下一篇>>