提问时间: 2008-07-24 17:33
悬赏分:50 浏览:116 次
我想把一个图片通过xml序列化的形式转换成一个xml文件。
我代码是这么写的:
Bitmap bmp = new Bitmap("baby.jpg");
XmlSerializer ser = new XmlSerializer(typeof(Bitmap));
// XML序列化
stream = new FileStream(@"users.xml", FileMode.Create, FileAccess.Write, FileShare.Read);
ser.Serialize(stream, bmp);
stream.Close();
// XML反序列化
stream = new FileStream(@"users.xml", FileMode.Open);
MyObject obj2 = (MyObject)ser.Deserialize(stream);
tream.Close();
其中,xml序列化部分没有异常,但一个28k的图片,序列化后得到的xml文件才1k,明显不对,而且用这个xml文件进行反序列化的时候MyObject obj2 = (MyObject)ser.Deserialize(stream);这行代码会出现异常,提示:XML 文档(4, 3)中有错误。参数无效。
开始序列化得到的xml文件内容是:
<?xml version="1.0"?>
<Bitmap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Palette />
</Bitmap>
请问问题处在哪里,如何修改?