Nhwk wrote:[color=blue]
> I have an unsigned char banner[96], which contains data for a 12x8
> bitmap file.
> I am attempting to construct and write to disk a .bmp file with this
> data.
>
>
> So far, I started by constructing the required .bmp header, by doing
> the following..
>
> char b[57];
> b[0] = 0x42;
> b[1] = 0x4D;
> b[2] = 0x98;
> b[3] = 0x04;
>
> etc, and have verified I have the correct header and palette info by
> using a hex editor to compare my output file to a valid .bmp file.[/color]
Why are you using a separate assignment statement for each byte?
Easier way: use a string or array initialisation for b.
Much easier way: do away with b and actually define the struct.
http://astronomy.swin.edu.au/~pbourke/dataformats/bmp/
[color=blue]
> Now here's my problem: I'm not quite sure how to append the unsigned
> chars (p->banner) to the file after i write b.
>
> std::ofstream bDump;
> bDump.open("bannerdump.bmp", std::ios::out | std::ios::binary);
> bDump.write((char*)&b, 58);
> bDump.write((char*)&p->banner, 96);
> bDump.close();[/color]
I presume that the offset variable in the header correctly matches the
point in the file where you start writing out the data? And that you've
got your dimensions and colour depth correctly matched?
[color=blue]
> However this doesn't work, as it doesn't seem to add enough data to
> the file as compared to the valid file when I view them in a hext
> editor. Casting the unsigned char to a (char*) seems kind of wrong.[/color]
<snip>
Good job there isn't a cast of unsigned char to char* in the code you've
provided then.
Stewart.
--
My e-mail is valid but not my primary mailbox. Please keep replies on
on the 'group where everyone may benefit.