Here is documentation for BMP: https://en.wikipedia.org/wiki/BMP_file_format#Pixel_array_.28bitmap_data.29
The short form is:
- 14 bytes BMP header (file information)
- 40 bytes DIB header (image information)
- pixels
You can see in within the DIB header section the two values 5 for the pixel dimensions, and a value of hex(18) for 24-bit color (RGB).
Of particular interest is the "Example 1" in the wiki which shows a HEX dump for a 2x2 image similar to what you have here. A few notes:
- a byte, visually, is a two digit couplet (the first byte in your image is 42).
- counting starts at 0, so "offset 31" is the 32nd byte.
- numbers are all HEX, so a hex(10) = dec(16). You can use windows calculator set to "programmer mode" if you need help converting.
- "byte order" is low-to-high, so a 4 byte value of "05 00 00 00" needs to be understood as "00 00 00 05"
- the RGB triplets in the bmp are reversed
Based on the hex dump and the documentation, your image is storing each pixel as an uncompressed RGB triplet. The first pixel is the triplet 24 1c ed
, but this is reversed, so it is hex(ed1c24) which which is indeed a red color. Note that there is a 00
pad after every row of 5 pixels. The documentation says this is for "byte alignment."
So to change a pixel from red to blue, you might alter one of the triplets from 24 1c ed
to ed 1c 24
.
As far as software, you would open the file (or a copy) with a Hex Editor, make the changes and save it. Simply using a text editor in "text edit mode" is not enough as the text symbol "0" is not the same as the binary numeric value of 0.
Open source Notepad++ has hex editing capability via plugins.
Regarding the larger question of how Paint makes an image, well, the program uses the documentation and standards to automate the process. Its mostly a matter of convention. The "image stream" (pixel data) is stored and manipulated in memory in a similar manner as you see in the uncompressed image file.