AQA 7517, section 4.5.6.4
A bitmapped (raster) image is made of a grid of tiny squares called pixels (picture elements). Each pixel is given a colour, stored as a binary number. When the pixels are displayed together, they form the picture.
How a bitmap is represented
For a very simple black and white image, each pixel needs just 1 bit: 0 for white and 1 for black. Here is a small 8 by 8 image of the letter T, with the bits stored row by row:
For more colours, each pixel needs more bits.
Key terms
Size in pixels
The size of an image in pixels is its width height. A photo that is 800 pixels wide and 600 pixels high has pixels.
Resolution
Resolution is how many pixels are packed into a given space, measured in dots per inch (dpi), where a dot is a pixel. A higher resolution gives a sharper, more detailed image, but needs more pixels and more storage. (The size of an image is also sometimes described as its resolution.)
Colour depth
Colour depth is the number of bits stored for each pixel. It decides how many different colours there can be:
| Colour depth | Colours | Typical use |
|---|---|---|
| 1 bit | 2 | Black and white |
| 4 bits | 16 | Simple graphics |
| 8 bits | 256 | Greyscale or a limited palette |
| 24 bits | 16 777 216 | Full colour photos (8 bits each for red, green and blue) |
In a 24-bit image, a pixel's colour is a mix of red, green and blue (RGB), with 8 bits (0 to 255) for each.
| Colour | Red | Green | Blue |
|---|---|---|---|
| Red | 255 | 0 | 0 |
| Yellow | 255 | 255 | 0 |
| White | 255 | 255 | 255 |
| Black | 0 | 0 | 0 |
Calculating the file size
Ignoring metadata:
where size in pixels = width height. The answer is in bits. Divide by 8 for bytes.
Example: an 800 by 600 image with 24-bit colour.
- Pixels: .
- Bits: bits.
- Bytes: bytes, which is about MiB (or 1.44 MB).
Example: a black and white image (1 bit per pixel): bits bytes.
width = 800
height = 600
depth = 24
bits = width * height * depth
print(bits // 8) # 1440000 bytes
What changes the size?
- Increase the dimensions or the resolution, and the file gets larger.
- Increase the colour depth, and the file gets larger, but the colours are richer.
- Double the width and height, and the file is four times bigger.
Metadata
A bitmap file also stores metadata, which is data about the image, in a header. Typical metadata includes:
- the width and height in pixels;
- the colour depth;
- the file format;
- sometimes the resolution (dpi), the date, and the camera details.
The program needs this to know how to read the bits and rebuild the image. It makes the file slightly larger than the calculation above suggests.
Worked example
Task: a 1280 by 720 image uses 16-bit colour. Calculate the file size in bytes (ignoring metadata), and how many colours are possible.
- Pixels: .
- Bits: .
- Bytes: bytes (about 1.76 MiB).
- Colours: .
Exam tip: write out the three steps: pixels = width height, bits = pixels colour depth, then divide by 8 for bytes. Say that metadata is ignored, unless the question asks for it.
Check yourself
How many different colours can be shown with a colour depth of 8 bits?
colours.
What is the size in bytes of a 100 by 50 image with 8-bit colour?
bits, which is bytes.
What is metadata in an image file? Give two examples
Data about the image, stored with it, such as the width, the height or the colour depth.
What effect does increasing the resolution have on image quality and file size?
It gives a sharper image with more detail, but the file is larger.