Chapter 5, Making a Jigsaw Puzzle Application
Pop-Quiz – how many bits in a byte?
Answer: 8. If only for the interest of mathematicians, it's good to know that a byte is 8 bits. A "bit" is a "binary digit", and when you start to think of bits in those terms you will see that a byte can store 2 to the power of 8 values in it ("binary" being Base 2). That came into play when looking at the length of a Pascal string (2 to the power of 8 is 256, hence the range of characters in a Pascal String is 0-255), and it helps you realize that if a picture is made up of one byte for each pixel's red, green, and blue values, it's a 24-bit picture. Once you add in another byte of data for the alpha channel, you have a 32 bit picture.
Pop-Quiz – getting the big picture
Answer: Depends on the nature of the image. SVG is a description of how to draw the image, whereas PNG is a description of the pixels in the image. In PNG that information is also data compressed, in a lossless way. For the example map, at its original size, a 24-bit PNG is half the size of the SVG file. There is a lot of data needed to describe the outlines of the US states! If the image needs to be enlarged, the PNG file would become bigger, while the SVG would remain the same file size. On the other hand, if an image was a rectangle of a diagonal gradient the SVG would be tiny, and the PNG would be huge, because there are no long runs of same colored pixels for the data compression to work well.
Pop-Quiz – calculate this!
Answer: 16,777,216 buttons. As with the discussion about "bits and bytes", red, green, and blue values combine to give us 2 to the power of 24 possible values. If you only used two of the colors, then the answer would have been 65,536.