这是一个演变: C# image binary serialization
我的课程非常简单:
public class TheClass2
{
public object myImg;
public int myInt;
}
为了序列化它,我必须将myImg从图像转换为对象
var ist = new TheClass2();
Image i = new Image();
ist.myImg= Convert.ChangeType(i, typeof(object));<-----this is not working
但是ist.myImg仍然是一张图片。
Thanx任何帮助 帕特里克
答案 0 :(得分:1)
是的,我错了。最后这么容易:
public class MyBitmapImage
{
public string strBitmapImage;
public bool IsImageEmbedded;
}
然后序列化为:
public static bool FileSerializer<T>(string filePath, T objectToWrite, out string strError, bool append = false)
{
using (Stream fileStream = File.Open(filePath, append ? FileMode.Append : FileMode.Create))
{
strError = string.Empty;
try
{
var binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(fileStream, objectToWrite);
return true;
}
catch (Exception exc)
{
strError = "Binary FileSerializer exception:" + exc;
return false;
}
}
}