Android pictures reduce picture size Keep the picture clear method

Source: Internet
Author: User
Tags webp

The processing of images in Android has been a rather annoying problem, and the annoyance is that an accident could cause oom.


Recently encountered a picture upload problem, image upload we must ensure that 2 points, one point is the size of the picture as small as possible, but the clarity of the picture has a certain guarantee, based on this we have two directions, one is to reduce the picture, the second is the quality of the picture is reduced.


For the reduction of the picture, we have a lot of methods, can be cropped, can be scaled, and another way to reduce the image is to reduce the quality, the use of this method after the image will become blurred, if we reduce the quality too much, we will find that our images have become a lot of pixels, have been image analysis of all know, Our images are represented by a pixel, the quality is reduced by a certain algorithm, and some can be used directly to a "field" of four pixels, according to our convention with a value to replace, this will be the original differentiated four pixels into an indistinguishable pixel point, When we reduce the quality of the image in the invisible phase of the human eye, in fact, we can not see the quality of the image of any direct changes, but once beyond our eyes to identify areas, we will have a very intuitive change.


The above two methods are now spread over the network more than two methods, but sometimes we find that using those two methods is still not up to our requirements, in the Internet to find some methods, I think it is good, which in one of my projects used in one of the methods.


1. Do not use JPG format pictures, use other format of the picture, I looked, found WEBP this format has a great advantage, one is that the format of the picture in the case of keeping and jpg the same information size, its size than JPG small 39% (online people say, the specific size you can look at the authoritative literature , I just want to express the size of a lot of reduced), read an article, said QQ inside the expression is the use of this format of the picture, but the resolution of this image is about 10 times times slower than the resolution JPG (no matter how slow can be determined is not very slow, The results of the online home test I do not remember very clearly about 100ms bar).

In the official API before Android 4.0 there is no relevant method provided, but after 4.0, the API provides the relevant methods.


Please refer to the article here, written very good: http://www.uisdc.com/image-format-webp-introduction


2. Use so file to compress jpg, read an article, people said inside why the Android version of the picture and the image of the iOS version of why the difference so much, people's team groped for a long time, it seems that Android and iOS are using the same package to compress the picture, But inside there is a parameter inside the Android default is False, but iOS seems to handle this parameter is better, so that the sharpness of iOS performance than Android clearer, can't find the original text, do not know whether this is the original, or attach a connection address: http:/ /www.geekfan.net/11651/


The 2nd method is our project is now used in the method, will use the NDK compiled, but it has provided the relevant so library, if you do not want to compile, directly copied out with the good, would like to directly to the company package name, but some of the header file is not found ... Did not change to, their C language Foundation is still poor point, later continue to study.

Android pictures reduce picture size Keep the picture clear method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.