Jump to content
  • Advertisement


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


How to create an image file in memory

This topic is 6204 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

my mfc app loads in a bmp and then converts it to my own format by doing the following: 1st it creates the MyImage header from the values in the bitmap file and writes it to a new file on disk. then using the data in BITMAP bmp.bmBits it writes out that data line by line:
for(int i=0; i
this then gives me a file on disk that is of the format i want it.
However I dont want to create a file on disk i want to store it in memory as a char * or something because i want to do other things to it like create a dat file and i dont want to have to create the file and then load it back in.
so i tried doing this:
char * FileData=new char[sizeof(header)+ width*bpp*height]
//copied header to new buffer

//so the data just copied wont be overwritten advance buffer

//then in the copy actual data bit i do:
for(int i=0; i
However much to my disappointment when i do FileData+=whatever the data that is supposed to be in the buffer before the new position is overwritten with garbage. And if I dont do FileData+=whatever then the data in FileData is overwritten each time something is added to it by the new data.
I am really not sure if i am even in the right area for doing what I want.
If anyone can understand my ramblings and can help i would be very grateful
Edited by - Zeke on June 28, 2001 10:42:47 AM

Share this post

Link to post
Share on other sites
I think it is because you are directly modifying the FileData pointer. I can''t explain properly why you shouldn''t do it - suffice to say that the program will lose track of what the pointer''s memory was, it''s size and so forth.

Basically, what you need to do is create another pointer and point it to that.


char * FileData=new char[sizeof(header)+ width*bpp*height];


char * FileDataBufptr = FileData; // choose a better name

and then use FileDataBufPtr for all your operations (memcpy, += whatever) and you shouldn''t corrupt your memory.

Hope thats right.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!