Android gets and compresses bitmap images through URI

Android gets and compresses bitmap images through URI

Many people will use media.getbitmap in onactivityresult to get the returned pictures when calling the gallery to select pictures, as follows:

However, the media.getbitmap () method is not a good way to obtain known URI images. Let's take a look at the source code of the media.getbitmap () method:

In fact, it is very simple and rough. It returns the original size bitmap. When the picture selected by the gallery is large, the program is likely to report oom.

In order to avoid oom, we need to improve this method and compress the picture before bitmapfactory.decodestream. The following is my improved code:

Call in onActivityResult

The problem of oom was solved, but another problem was encountered. The pictures returned after taking photos with Samsung mobile phone or selecting photos turned 90 degrees.. Hard pressed Android programmers.. Then change..

Improve the code in onactivityresult:

If you have any questions, please leave a message or go to the community of this site for communication and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

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