Encoding Images: Bitmaps
All pictures on a computer are stored as 1s and 0s
The simplest way is as a BITMAP image by turning your picture into pixels.
Bitmap Images
A pixel is a single block of colour that makes up a picture. It is a bit like a tile in a mosaic.
By creating a grid of pixels we can create a black and white picture using pixels.
By recording all the black pixels as 1s and all the white pixels as 0s we can store an image as binary.
Adding Colour
The problem with using just 1 bit (a 0 or 1) per pixel is that we can only use 2 colour.
By using more bits per pixel we can store the information for more colours.
By using 2 bits per pixel we can store the information for 4 colours.
For example we might decide to use the following:
00 = white
01 = red
10 = yellow
11 = black
We can then improve our image above so it now looks like this:
This of course means that the file is twice as large instead of 8 bytes of data we now have 16 bytes.
We can add more colours to our palette by increasing the number of bits per pixel:
1 bit = 2 colours
2 bits = 4 colours
3 bits = 8 colours
4 bits = 16 colours
5 bits = 32 colours
6 bits = 64 colours
7 bits = 128 colours
8 bits (1 byte) = 256 colours
As we increase colour depth we also increase file size.
Adding detail
Pixels Per Inch
When creating bitmap images we measure the resolution (pixel density) using Pixels Per Inch (ppi).
The greater the ppi, the greater the detail but also the greater the file size.
The picture of a man below is made up of pixels on an 8 by 8 grid, and to be fair is a bit rubbish. There are no smooth lines and very little detail.
To add more detail I will need smaller pixels and more of them!
In the picture below I am now using a 16 pixel by 16 pixel grid. Where there was once 1 pixel, there is now 4.
This file is 4 times bigger (instead of 16 bytes it is now 64 bytes) because it has to store 4 times as many 0s and 1s than the previous image.
To add more detail still, I will need smaller pixels and more of then.
In the picture below I am now using 32 pixels by 32 pixels. Where there was once 1 pixel in the original image, there is now 16.
Press the green flag.
Click the arrows to change the resolution of the image.
As the resolution, measured in Pixels Per Inch (ppi) increases, notice how the number of bytes required to store the image increases.
Can you guess who it is?
KeyWords
Pixel
Picture Element.
An individual block of colour that makes up a raster image.
The colour of each pixel is saved as a binary value.
Colour Depth (or bit depth)
The number of bits used to store the colour of each pixel.
The more bits per pixel increase the number of possible colours, but also increases the file size.
Resolution
The resolution of an image is measured in Pixels Per Inch (PPI)
The higher the PPI, the better quality the image but the image will take up more memory.
File Size
The amount of memory a file takes up when saved. You can calculate the size of a bitmap image using the formula:
File Size = width (in pixels) X height (in pixels) X bit depth
Activities
Activity 1: Program a simple 8x8 bitmap graphic using BBC Basic
Activity 2: Program a simple 16x16 bitmap graphic using BBC Basic