Archived

This topic is now archived and is closed to further replies.

saving a texture to file

This topic is 4985 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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"

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites