
About reading bmps
ok, I had an idea for my game, that i would use a picture to draw the level, literally, by drawing it in paint or whatever, then running through and testing each pixel, for example:
pixel color:::draw this tile at that x,y pos
0000FF:::box
00FF00::
latform
FF0000:::starting position of character
etc etc
and then it would put that in to an array...
so, what i need to know is this, how do you read bitmaps? i''ve looked at them in notepad and all that stuff, but of course, you can''t learn much from that, hehe.
code would be nice, and an explanation as to how it works so i can actually use it, hehe
-Jverkoey

Most bitmap loaders return an array of pixels, 3 bytes if its RGB, and a BITMAPINFOHEADER or something similar. From that, you can get width and height of the bitmap array. Run a couple of for loops and you can scan through the data no problem. Just do a google search for bitmap loaders, or maybe NeHe has a link or two.
If you''re really in need of direction, email me and I''ll help out.
If you''re really in need of direction, email me and I''ll help out.
struct BITMAPINFOHEADER{ unsigned int size; int width; int height; unsigned short planes; unsigned short bitCount; unsigned int compression; unsigned int sizeImage; int xPelsPerMeter; int yPelsPerMeter; unsigned int clrUsed; unsigned int clrImportant;};
thats the bitmap header. it''s the first 40 bytes of any .bmp file.
the remaining bytes within the file is the data for the image.
eg:
assuming you can load a file as binary data, (I''ve used my own file IO class as an example here - although it doesn''t work quite like this in practise)
BYTE * rawFile = FileIO::loadFileBinary("myBitmap.bmp");if (!rawFile)// opsBITMAPINFOHEADER header;memcpy(rawFile,&header,sizeof(header));// copy in the data into the header...if (header.bitCount!=24)// It''s a palleted bitmap, or such, which is more complex..BYTE * bitmap = new BYTE[header.width*header.height*3];memcpy(bitmap,rawFile + sizeof(header) ,header.width*header.height*3);// tadadelete [] bitmap;delete [] rawFile;
correct me if I''m wrong here in some way, I''m just writing as a guess...
| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
Wotsit seems to be a good source of information about file formats.
Visit our homepage: www.rarebyte.de.stGA
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement