saving a texture to file

Started by
6 comments, last by Hybrid666 20 years ago
hi, i need to save a texture to a file (32-Bit BMP is fine) and am unsure about how to proceed. this is the data i have about my bitmap: HDC hdcTemp; //DC to hold Bitmap HBITMAP hbmpTemp; //holds Bitmap temporarily BITMAPINFO bi = {0}; //type of Bitmap requested DWORD *pBits = 0; //pointer to Bitmap bits how can i save this into a bmp file? (ps im using modified NeHe texture loading code for custom texture generation within a program, and want to save the generated textures to files.. all the above data types have all the bitmap data in them.) any help wud b much appreciated Hybrid
Advertisement
well, one way to do it would be to look up the bitmap file format on the web (google search: "bmp file format") and then write your own bmp file exporter. the other way to do it would be to search the web for a pre-written bmp file exporting library and just use that with the data you have.

-me
If I remember correctly, there are just a few important structures in the Win32 API that are used to store all the information on a bitmap, and writing the bitmap to a file is pretty much as simple as writing each of the structures out to a single file, byte-for-byte, in the proper order. And then, reading the bitmap from the file is just as easy.

Look up BITMAPFILEHEADER and BITMAPINFOHEADER (or BITMAPV4HEADER or BITMAPV5HEADER, depending on platform). Actually, just go to MSDN''s bitmap documentation, or more specifically, their section on storing an image.

Most of the greatest evils that man has inflicted upon man have come through people feeling quite certain about something which, in fact, was false.

-Bertrand Russell, Unpopular Essays, "Ideas That Have Harmed Mankind"
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
help''s been great so far thanks - but still stuck with one thing

it now saves a file of the correct size, with all the correct header info (i think) ... well, i can open the created bmp in windows .. but, the colours are all screwed up :\

the texture code i have uses a DWORD* to the pixels, but the code on the MSDN uses a BYTE* and i cant seem to convert between the two at all using casting (file seems to save ok with no errors but in windows it wont open it, says drawing failed)

also tried using the code on the msdn to get the bits into a BYTE* data type but that gives me the screwed up colours!!

argh driving me mad!!

thanks again
Hybrid
another thought - an alternative wud b if sum1 knew how i could set pixel data in an LPBYTE type on a per pixel basis?
more progress... now i have valid bitmaps that look correct, but the colours are still wrong - white appears cyan (kinda light blue)

any ideas?
Double-check the color order of your data and see if you have the padding between the rows correct (you need a few empty bytes if the row lenght is not a multiple of 4)
Or you could use a package like DevIL...

This topic is closed to new replies.

Advertisement