• Announcements

Archived

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

How to create an image file in memory

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:
bytes=oldbm.pwide*oldbm.wide;
source=(char*)bmp.bmBits;//SurfacePointer();
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:

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

//then in the copy actual data bit i do:
bytes=oldbm.pwide*oldbm.wide;
source=(char*)bmp.bmBits;//SurfacePointer();
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
thanks
Edited by - Zeke on June 28, 2001 10:42:47 AM


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.

i.e.

then

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.

-Mezz

Share on other sites
That worked like a charm! Thankyou very much

• Partner Spotlight

• Forum Statistics

• Total Topics
627652
• Total Posts
2978421

• 10
• 12
• 22
• 13
• 33