What is the best pixel format

Michael Jentsch

Android offers the option of using different bitmap configurations for bitmaps. A bitmap configuration describes how the pixels are stored in the file. This affects the quality (e.g. color depth) and the ability to display transparent colors.

Android distinguishes 4 different Bitmap.Config types

 

Bitmap.Config ALPHA_8

With the Bitmap.Config ALPHA_8, each pixel is saved as a single alpha channel. This configuration requires 1 byte of memory for each pixel of the image. This can be useful for saving masks efficiently.

 

Bitmap.Config ARGB_4444

Bitmap.Config ARGB_4444 has been deprecated since API level 13. Because of the poor quality of this configuration, you should do without the Bitmap.Config ARGB_4444 and use ARGB_8888 instead.

 

Bitmap.Config ARGB_8888

All 4 channels in the image (RGB and Alpha) are saved with an 8-bit precision. This configuration is very flexible and offers the best quality. Since each pixel is stored in 4 bytes, this configuration requires a lot of memory and a lot of computing power to process the image data. Therefore, ARGB_8888 should be used if the highest quality and transparency is required.

 

Bitmap.Config RGB_565

With the RGB_565 pixel format, each pixel is saved in 2 bytes and only the RGB channels are available. RGB_565 bitmaps do not contain any transparency.

  • Red is saved with 5 bit precision (32 possible values)
  • Green is saved with 6 bit precision (64 possible values)
  • Blue is saved with 5 bit precision (32 possible values)

RGB_565 can be useful when using bitmaps that do without transparency and do not require high color depth. The advantage of RGB_565 is that these bitmaps can be drawn faster and require significantly less memory.
In my experiments I observed an approx. 15% better performance.

 

Create RGB_565 file with Gimp

Creating RGB_565 JPGs is not that easy. For Photoshop, for example, there is an extra plug-in for this task. But since I'm a Gimp user, that doesn't help me much.
However, there is also a way to create an image in Gimp that is saved as RGB_565. In Gimp you have to do that dither16bit.scm script and the following 4 pallets are installed.

  • 1BitGrayscale.gpl
  • 4BitGrayscale.gpl
  • 5BitGrayscale.gpl
  • 6BitGrayscale.gpl

Download the pallets:
Grayscales.zip

The 4 palettes must be copied to the% GIMP_HOME% / share / gimp / 2.0 / palettes / folder. If the pallets are available, you can see the following 4 new pallets in the “Pallets” dialog.

Now the dither16bit.scm script has to be copied into the folder% GIMP_HOME / share / gimp / 2.0 / scripts. Unfortunately there is no refresh button here and Gimp has to be restarted once before the plugin can be used. Then you will find the following menu items in the menu with which you can convert your image into an RGB_565 bitmap.

 

Conclusion

Everyone has to decide for themselves which pixel format best suits their own requirements. In any case, I will use the format more often in the future. In most cases, 65536 different colors are enough for me if, for example, I need a drawable for a button or another component.


My apps in the Google Play store


Posted in General