将二进制文件转换为图像

将二进制文件转换为图像

问题描述:

当我将二进制数据转换为文件并执行文件时,我看到图形文件的此错误

Windows照片查看器无法打开此图片,因为该文件似乎已损坏或损坏>




这是我的方法File.WriteAllBytes(path,fileContent);

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);

从未尝试过这种方式...

我认为序列化方法(ObjectToByteArray)创建的内存转储以不同于Bitmap.Save(流,格式)的格式返回字节。

因此我建议您通过恢复序列化方法的步骤来反序列化图像,然后使用Bitmap.Save(文件名,格式)将图像写入磁盘。
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).