Use of webp in Android

Source: Internet
Author: User
Tags webp

Use of webp in Android
1 webp formatThis is a unified Internet image format launched by Google. Its advantage lies in the same image content, which is much smaller than the existing image format, this means that the transmission speed is fast, the memory consumption is reduced, and the loss of image processing is reduced. The specific compression method adopted by webp will not be explored. You can find a small tool to convert existing images into webp format.2. Use of webpIn the project, to reduce the size of the apk, we need to convert all part of the image resources into webp images. The size is much less, but webp is in the android system version, only after 4.0 will be supported by default, that is, you put the webp Format Image under the drawable resource R. the java file will generate an int identification number, so that you can use the resource in the Code, such as setting images for imagview. In addition, we also used another method in the project to use the webp image, compress it into a zip package, put it in the memory folder, and then read and parse it, the process is the same as that of parsing images in png format to form a bitmap, but webp is used here. The code is now pasted as follows:

public Bitmap readBitmapFromZip(ZipResourceFile mZipRes, String resId, BitmapFactory.Options mOpt){            Bitmap bmp = null;            if(mZipRes != null){                    InputStream in = null;                    try{                             in = mZipRes.getInputStream(resId + .webp);                          }                      catch (Exception e){ e.printStackTrace()};                              }                                    if(in != null) {                                                 bmp = BitmapFactory.decodeStream(in);                                                     }                         try{                                    if(in != null)                                             in.close();                                        }                                    catch(Exception e){ e.printStackTrace()};                                                                return bmp;}

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.