Click here to Skip to main content
15,904,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i convert binary data to file and execute the file i see this error for graphic file
Windows Photo Viewer can't open this picture because the file appears to be damaged or corrupted


this is my method File.WriteAllBytes(path, fileContent);
Posted
Comments
[no name] 15-Apr-14 2:51am    
What were you expecting? What is fileContent? Not enough code here to make any sense.
Mahdi_kishislan 15-Apr-14 3:01am    
file content is byte array variable (byte[]) that contain my binary data.
this is my method that convert data from sql to bye[] in c#
public static byte[] ObjectToByteArray(Object obj)
{
if (obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}

1 solution

Never tried it this way...
I think that the "memory dump" created by your serialization method (ObjectToByteArray) returns the bytes in a different format than Bitmap.Save(stream, format).
Hence I'd suggest you de-serialize the image by reverting the the steps of your serialization method, and then write the image to disk with Bitmap.Save(filename, format).
 
Share this answer
 
Comments
Mahdi_kishislan 17-Apr-14 2:32am    
tnx

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