View Full Version : write bmp
Reanimated
05-05-2007, 05:50 AM
Hi,
I'm trying to output a plain red bitmap using only the C++ stl (so I can't use windows.h). How would I go about doing this? At the moment, I've imported a (working) bitmap header file. I read this file in, and then output it to a new file using streams. The new file, which is a 200 x 200 bitmap file, is created. However, when I open it in windows picture viewer, it says drawing failed. What information do I append on the end of it in order to make it plain red?
Thanks
Desktop Gaming
05-05-2007, 05:55 AM
Hi,
I'm trying to output a plain red bitmap using only the C++ stl (so I can't use windows.h). How would I go about doing this? At the moment, I've imported a (working) bitmap header file. I read this file in, and then output it to a new file using streams. The new file, which is a 200 x 200 bitmap file, is created. However, when I open it in windows picture viewer, it says drawing failed. What information do I append on the end of it in order to make it plain red?
Thanks
You got the file spec off www.wotsit.org ?
Reanimated
05-05-2007, 06:56 AM
I ended up reaching this site (http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html). However, I still don't really understand it properly. RGBQUAD a built in data structure, or do I create a struct?
spellcaster
05-05-2007, 07:44 AM
you have to create pretty much every struct yourself. The structs refer all to types defined by the win32 api - which you don't want to use.
Reanimated
05-05-2007, 08:02 AM
Assuming I've created all the required structs, would I then just adjust the pixels RGB value, by iterating through a two dimensional array/vector? Seeing as there is no Byte primitive type, I assume I'd use a Char (as it's 8 bytes long). But how would I use a char to represent a value between 0 and 255? Or have I missed something...
Thanks for the help
I use TGA for build-in screenshot stuff.
For that you simply write a few bytes { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 } for the header. Then width, height and bpp (24) as little endian 2 byte shorts. And finally the pixel data in BGR order. Amazingly simple, isn't it?
Reanimated
05-06-2007, 06:15 PM
I need to use a bitmap (simply for this project). How would I go about reading every pixel and storing it in an array?
Depends on the API you're using. With OpenGL for example you simply use glReadPixels.
spellcaster
05-06-2007, 09:53 PM
But how would I use a char to represent a value between 0 and 255? Or have I missed something...
Thanks for the help
You'd declare it aus unsigned char and then just work with it. Please keep in mind that there are quite a bit of BMP variants (2 to 32 bits, Windows and OS/2 Format, etc). I had to write one in java some time ago and while it was not difficult it was more work than I had expected ;)
Reanimated
05-07-2007, 06:21 PM
Thanks for the help, I've managed to get it working. What was really annoying was that it was just one line of code preventing it from working properly :mad: . Guess thats programming though.....:D
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.