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;}