Taking photos with Android system and cutting pictures with Android clip

Changing a user's Avatar in an application generally has two methods: taking photos and selecting photos from the gallery. Now there are many open-source online, but many are too complex. The Android clip library is relatively small, the code is not complex, and it is more suitable, but it does not have the function of taking photos, so we need to integrate it ourselves.

Call the system camera to take photos

1. Return to thumbnail photos

Override the onactivityresult method and the system camera will return a thumbnail

1. Return the full picture. If it is a full picture, it usually exists in the external storage space of the mobile phone. At this time, you need to read and write external permissions

Wrte is not required at 4.4 and above_ EXTERNAL_ Storage permission, so we added Android: maxsdkversion = "18"

Because it is a full picture, the picture will generally be large. We can't return all the data like the above, otherwise oom will easily appear. Therefore, when starting photographing, set a specified path to save the picture. After photographing successfully, we can directly use this path

When creating an image URI, fileprovider is used. Fileprovider is just a subclass of ContentProvider. Used to facilitate file sharing. The fileprovider needs to be configured in manitext.xml under the node

The contents of the authorities should be the same as the second parameter in the fileprovider. Geturiforfile() method.

Also configure Android: resource RES / XML / file_ paths.xml

Crop images using Android crop open source library

Android clip is a relatively simple image clipping library. See GitHub's demo for specific use. We use it together with photography here. We are ready to take photos above. We need to process it in the onactivityforresult () method

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