Sometimes you see other people using bitmap to use argb_8888/rgb_565 parameters, so what are these parameters? What is the impact on bitmap?
They are the four enumeration types of Bitmap.config.
(The ARGB are alpha transparency and red, green, blue three colors respectively)
argb_8888:8 bits are used to record 4 values, so each pixel occupies 32 bits.
argb_4444:4 bits are used to record 4 values, so each pixel occupies 16 bits.
rgb_565: Use 5-bit, 6-bit, and 5-bit to record RGB tri-color values, so each pixel occupies 16 bits.
Alpha_8: The comment should be to not save the color value, save only the transparency (8 bits), each pixel will occupy 8 bits.
So what's the impact on bitmap?
This is a comparison of argb_8888 as a benchmark.
argb_4444: The memory footprint is reduced by half, but the image distortion of each value is very serious, the parameter itself is deprecated.
rgb_565: The memory footprint is reduced by half, the transparency is discarded, and the tri-color value is partially lost, but the image distortion is small.
Alpha_8: Memory footprint is not reduced! According to the explanation of the comments the personal understanding should be reduced by 3/4 of the memory footprint, and the picture is no different from the argb_8888.
(Alpha_8 found the information is not much, I hope that a master can help me with doubts)
Summarize:
Because the argb_4444 is not recommended and the Alpha_8 effect is unclear. Most of us use argb_8888 and rgb_565.
RGB_565 can greatly reduce the cost of memory in the case of image quality, which is a way to solve oom. However, it is important to note that rgb_565 is not transparent, and if the picture itself needs to preserve transparency, then rgb_565 cannot be used.
Test code: try {URL url = new URL ("http://h.hiphotos.baidu.com/image/pic/item/b21c8701a18b87d6b025e513040 828381f30fd53.jpg "); HttpURLConnection connection = (httpurlconnection) url.openconnection (); InputStream in = Connection.getinputstream (); Bytearrayoutputstream content = new Bytearrayoutputstream (); byte[] buffer = new BYTE[10 * 1024]; int count; while ((count = in.read (buffer)) > 0) {content.write (buffer, 0, count); } byte[] data = Content.tobytearray (); Bitmapfactory.options options1 = new Bitmapfactory.options (); Options1.inpreferredconfig = Bitmap.Config.ARGB_8888; Bitmap Bitmap1 = bitmapfactory.decodebytearray (data, 0, Data.length, options1); System.out.println ("Bitmap argb_8888 Length" + bitmap1.getbytecount ()); System.out.println ("Bitmap ARGB_8888 Length "+ bitmap1.getrowbytes () * bitmap1.getheight ()); Bitmapfactory.options options2 = new Bitmapfactory.options (); Options2.inpreferredconfig = Bitmap.Config.RGB_565; Bitmap BITMAP2 = bitmapfactory.decodebytearray (data, 0, Data.length, options2); System.out.println ("Bitmap rgb_565 Length" + bitmap2.getbytecount ()); System.out.println ("Bitmap rgb_565 Length" + bitmap2.getrowbytes () * bitmap2.getheight ()); Bitmapfactory.options options3 = new Bitmapfactory.options (); Options3.inpreferredconfig = Bitmap.Config.ALPHA_8; Bitmap bitmap3 = bitmapfactory.decodebytearray (data, 0, Data.length, OPTIONS3); System.out.println ("Bitmap alpha_8 Length" + bitmap3.getbytecount ()); System.out.println ("Bitmap alpha_8 Length" + bitmap3.getrowbytes () * bitmap3.getheight ()); Bitmapfactory.options options4 = new BITMAPFACTORY.OPtions (); Options4.inpreferredconfig = Bitmap.Config.ARGB_4444; Bitmap BITMAP4 = bitmapfactory.decodebytearray (data, 0, Data.length, OPTIONS4); System.out.println ("Bitmap argb_4444 Length" + bitmap4.getbytecount ()); System.out.println ("Bitmap argb_4444 Length" + bitmap4.getrowbytes () * bitmap4.getheight ()); } catch (Exception e) {e.printstacktrace (); }
(BITMAP) argb_8888/rgb_565/alpha_8/argb_4444 detailed