Advertisement

Second question about bitmaps.

Started by January 19, 2020 10:02 PM
5 comments, last by fleabay 4 years, 10 months ago

I am working on a bitmap enlarger program. This is my second topic this week. When I look at the bitmap structure on Wikipedia (https://en.wikipedia.org/wiki/BMP_file_format) it shows hex values such as : 46 00 00 00. This represents that the size of the bmp being 70 bytes (offset 2h.) This shows that the remaining three zeros are nothing but placeholders. Now, what if I need to use a zero that actually changes a hex value, how would this be done? I am writing it to a file.

Thank you,

Josheir

This is the file write for some string hexbuffer such as : 0100FFA0.

ofstream myfile;
myfile.open("C:/Users/joshe/file7.bmp", ios::binary);  
for (int i = 0; i < 8; i++)
{
r = cal(hexbuffer[i]) * 16 + cal(hexbuffer[i+1]);
myfile << r;
i++;
}
myfile.close();
int cal(char c)
{
int h = 0;
if (c <= '9' && c >= '0') return c - '0';
if (c <= 'f' && c >= 'a') return c - 'a' + 10;
if (c <= 'F' && c >= 'A') return c - 'A' + 10;
return(1);
}

Advertisement

A more realistic value would be: 01000000.

Also, r is of type char.

Looks as though placing the zeros on the left might work. Still, I'd have to read though.

Are you asking for help? Google “endianness” to understand why the 46000000 is 00000046.

Check out these…

10:15 - 26:00 - Casey Muratori - Endianness

https://youtu.be/0CB1mYS5wBc?t=615

Handmade Hero - Loading BMPs

https://www.youtube.com/watch?v=USFTH9mcaKw

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

This topic is closed to new replies.

Advertisement