Android selects album photos and returns the implementation code of the function

First, for reading and writing operations, declare permissions in androidmanifest.xml:

Call system Album:

Then call back:

Encapsulate the image related operations into an imgutil class for easy use:

In order to be compatible with new and old versions of mobile phones, we made a judgment. If the mobile phone is a 4.4 or above system, we will call the handleimageonkitkat() method to process the picture, otherwise we will call the handleimagebeforekitkat() method to process the picture. The reason for this is that the Android system starts from version 4.4. The pictures selected from the album no longer return the real URI of the picture, but an encapsulated URI. Therefore, if the mobile phone is above version 4.4, the URI needs to be parsed.

Of course, it is not recommended to directly use bitmapfactory.decodefile (imgpath) to obtain bitmap after obtaining the image path, because some images may be very large, and loading them directly into memory may lead to program crash (I've encountered it.. you can directly load the original image taken by the high pixel of the mobile phone and have a try =). Therefore, it is better to compress the picture properly first, and then load it into memory (implemented in the above code).

summary

The above is the implementation code of Android photo album selection and return function introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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