Display a BMP Image

Introduction

The BMP file format, or bitmap, is a raster graphics image file format used to store bitmap digital images, independently of the display device. (Wikipedia)

Project #1

In this project you will access the raw bytes of a BMP image file and write the pixels into a graphics window.

To see code that can access BMP file as bytes click HERE .

Use the graphics library graphics.py. Click HERE for more information.

Note: graphics.py is slow, but that is OK. This is learning exercise. In the real world a more efficient module would be used.

Project #2

Create an interactive BMP 24bit pixel row padding calculator. Ask the user to enter the number of pixels. Display the number of pixels and the padding.

Project #3

The same as Project #1 except use Python's PIL module.

A suggestion on program design

  1. read the BMP file into a byte array
  2. get the image width and height from the header
  3. create a graphics window using the width and height
  4. get the start of (the offset to) the image pixels from the header
  5. process one pixel at a time
  6. write each pixel into the graphics window

First create the code to access BMP header and pixels. Then add the graphics.

A suggestion on creating BMP test file

Use a paint program (like Windows paint) to create small BMP test files. (Use them to debug your code.)