CHAPTER 9: Android Graphic Design: Making Your UI Designs Visual 313
It is interesting to note that many alpha channels which are used to mask objects in an image will
compress very well. This is because alpha channels contain large areas of white (opaque) or black
(transparent), with very little grey value in the pixels along edges between the two colors to anti-alias
the mask. These grey values in an alpha channel are essentially the anti-aliasing values, and as you
now know, are used to provide visually smooth edge transitions between the masked object and the
imagery which will be used behind it.
The reason for this is because in an alpha channel image mask, the 8-bit transparency gradient is
defined using a white to black spectrum (gradient) which defines the alpha channel transparency.
So these grey values along the edges of each object in the mask are essentially averaging, or
blending, the color of the (RGB) object with color in the target background image. This essentially
provides real-time anti-aliasing for the image element (object) on your transparency layer with any
background image that is placed behind it.
Android Image Formats: Lossless Versus Lossy
Android supports several popular digital image file formats, some of which have been around for
decades.
These range from the decades-old Compuserve GIF (Graphic Information Format) and the Joint
Photographic Experts Group (JPEG) formats, to the more recent PNG (Portable Network Graphics)
and WebP (Web Photo) formats. I will cover these in order of origin, from the older (and less
desirable) GIF, to the newest WebP format.
Compuserve GIF is fully supported by the Android OS; however, it’s not recommended for use! GIF
is a lossless digital image file format, as it does not throw away any image data to achieve its better
compression result. This is because a GIF compression algorithm (codec) is not as refined (read:
powerful), and it only supports indexed color, which we covered earlier in the chapter. That said, if all
your image assets are already created, and they use the GIF format, you will still be able to use them
without any problems (other than the resulting quality to file size ratio) in an Android app.
The next oldest digital image file format which Android supports is JPEG, which uses the truecolor
color depth, instead of an indexed color depth. JPEG is a lossy digital image file format, because it
throws away the original image data in order to be able to achieve a smaller file size. The file sizes
achieved by using the JPEG algorithm can be an order of magnitude (10X) smaller than the original
raw uncompressed image data.
It is important to note that the original (often referred to using the term “raw”) uncompressed image
data is unrecoverable after compression by the JPEG codec’s encoder has taken place. For this
reason, you will want to make sure you have saved your original uncompressed image file before you
“run” the image through the JPEG compression algorithm.
If you zoom into a JPEG image after compression, you will see discolored areas which clearly were
not present in the original image. These “degraded” areas in the JPEG image data are termed
compression artifacts in the digital imaging industry, and compression artifacts only occur when
you utilize lossy image compression. This is the primary reason why the JPEG file format is not the
most highly recommended digital image format for use in Android.