Perform calculations to estimate the file size for a bitmap image

Resources | Subject Notes | Computer Science

Multimedia - Bitmap Image File Size Calculation

Multimedia - 1.2 Bitmap Image File Size

Objective

To perform calculations to estimate the file size for a bitmap image.

Understanding Bitmaps

Bitmaps are a common way to represent images digitally. They store image data as a grid of pixels, where each pixel has a specific color. The file size of a bitmap image is determined by several factors, primarily the image dimensions and the number of bits used to represent each pixel.

Key Factors Affecting File Size

  • Image Dimensions: The width and height of the image in pixels. Larger dimensions generally lead to larger file sizes.
  • Colour Depth: The number of bits used to represent each pixel's colour. This determines the number of possible colours.
  • Colour Type: The specific format used to represent colours (e.g., index colour, RGB).
  • Compression: Whether the image is compressed and the type of compression used (e.g., uncompressed, Run-Length Encoding (RLE), JPEG). Compression reduces file size but can sometimes affect image quality.

Calculating File Size (Uncompressed)

For an uncompressed bitmap image, the file size can be estimated using the following formula:

$$ \text{File Size (bytes)} = \text{Image Width (pixels)} \times \text{Image Height (pixels)} \times \text{Bits per Pixel} $$

The Bits per Pixel depends on the colour depth:

  • Black and White (1-bit): 1 bit per pixel
  • Grayscale (8-bit): 8 bits per pixel
  • True Colour (24-bit): 24 bits per pixel (8 bits for Red, 8 bits for Green, 8 bits for Blue)
  • True Colour with Alpha (32-bit): 32 bits per pixel (8 bits for Red, 8 bits for Green, 8 bits for Blue, 8 bits for Alpha)

Example Calculation

Let's calculate the estimated file size for a grayscale image:

Image Dimensions: 640 pixels wide x 480 pixels high

Colour Depth: 8 bits per pixel (grayscale)

Calculation:

Parameter Value
Image Width 640 pixels
Image Height 480 pixels
Bits per Pixel 8 bits

$$ \text{File Size} = 640 \times 480 \times 8 = 24,576,000 \text{ bytes} $$

This is approximately 24.58 MB.

Compression and File Size

When images are compressed, the file size is reduced. The amount of reduction depends on the compression algorithm and the compression ratio. Common compression methods include:

  • Run-Length Encoding (RLE): Simple lossless compression, effective for images with large areas of the same colour.
  • JPEG: Lossy compression, suitable for photographs. It reduces file size by discarding some image data.
  • PNG: Lossless compression, suitable for images with sharp lines and text.

Further Considerations

The calculations above provide an estimate for uncompressed images. Real-world file sizes can vary depending on the specific image format, the presence of headers and metadata, and the level of compression used.