Click here to Skip to main content
15,888,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1.how to save char * to a image file?
2.how to convert char * to TMemorystream * type?

C++
void process(char* data, int length)
{
   //the data is a image
}


I have try follow code,but display a blank photo.

C++
TMemoryStream * MemoryImageStream=new TMemoryStream;
  MemoryImageStream->Position=0;
  MemoryImageStream->Write(photo,len);
Posted
Comments
Jochen Arndt 25-Jun-14 4:28am    
What kind of image data do you have?
What kind of image file do you want to save?
Image files usually have a header containing information of the image followed by the image data.
So you have to create the header, convert the data if necessary, and write header and data to file.

1 solution

You need to assign the appropriate size to the TMemoryImageStream object.

Instead of:

C++
TMemoryStream * MemoryImageStream=new TMemoryStream;
    MemoryImageStream->Position=0;
    MemoryImageStream->Write(photo,len);


change it to:

C++
TMemoryStream * MemoryImageStream=new TMemoryStream(len);
    MemoryImageStream->Position=0;
    MemoryImageStream->Write(photo,len);


See also:
http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900