你好,我想問你一個問題。以XML格式編寫課程的一部分
我創建了一個Person類,我寫了人名,姓氏,ID和圖像。
現在我想把這個類保存爲.xml和image。我找到了將類保存爲.xml的解決方案,但不會將任何圖像保存到.xml文件中。
private void SaveasXML()
{
XmlSerializer serializer = new XmlSerializer(typeof(BindingList<Person>));
FileStream fileStream = File.Create(Application.StartupPath + "\\Data\\Person.xml");
serializer.Serialize(fileStream, New_Xml_Person);
}
我想用圖像保存所有信息到.xml文件中。要將圖像保存爲.xml文件,應將其轉換爲base64string
。我知道但我無法使用它。
有什麼建議嗎?謝謝。
你需要保存在XML文件中的實際圖像還是你只想路徑保存? –
你如何在課堂上存儲圖像?你能分享你的人員代碼嗎? – thepirat000
圖像可以保存爲已轉換的base64strings。我Person類的最後拿到集部分: \t \t [XmlElementAttribute( 「圖片」) \t \t公衆的byte [] PictureByteArray \t \t { \t \t \t得到 \t \t \t { \t \t \t \t如果(picture!= null) \t \t \t \t { \t \t \t \t \t TypeConverter BitmapConverter = TypeDescriptor.GetConverter(picture.GetType()); (byte [])\t BitmapConverter.ConvertTo(picture,typeof(byte [])); \t \t \t \t \t \t \t \t \t} \t \t \t \t其他 \t \t \t \t \t返回NULL; \t \t \t} \t \t \t \t \t \t設置 \t \t \t { \t \t \t \t如果(值!= null) \t \t \t \t \t picture = new Bitmap(new MemoryStream(value)); \t \t \t \t別的 \t \t \t \t \t圖象= NULL; \t \t \t} \t \t} – user3478916