資源簡介
圖片和XML格式互換,非常簡單,一看就明白。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.Drawing;
using?System.IO;
namespace?圖片和xml格式互換
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?string?MyFile?=?““;????//文件名
????????private?string?MyFileExt?=?““;//擴展名
????public?System.Drawing.Imaging.ImageFormat?GetImageType(string?str)?//擴展名得到文件類型
????{
????????if?(str.ToLower()?==?“jpg“)
????????{
????????????return?System.Drawing.Imaging.ImageFormat.Jpeg;
????????}
????????else?if?(str.ToLower()?==?“gif“)
????????{
????????????return?System.Drawing.Imaging.ImageFormat.Gif;
????????}
????????else?if?(str.ToLower()?==?“tiff“)
????????{
????????????return?System.Drawing.Imaging.ImageFormat.Tiff;
????????}
????????else?if?(str.ToLower()?==?“icon“)
????????{
????????????return?System.Drawing.Imaging.ImageFormat.Icon;
????????}
????????else?if?(str.ToLower()?==?“image/png“)
????????{
????????????return?System.Drawing.Imaging.ImageFormat.Png;
????????}
????????else
????????{
????????????return?System.Drawing.Imaging.ImageFormat.MemoryBmp;
????????}
????}
????private?void?button1_Click(object?sender?System.EventArgs?e)
????{
????????OpenFileDialog?openFileDialog1?=?new?OpenFileDialog();
????????openFileDialog1.InitialDirectory?=?“c:\\“;
????????openFileDialog1.Filter?=
?????????????“PNG(*.png)|*.png|Gif(*.gif)|*.gif|Jpg(*.jpg)|*.jpg|所有圖象文件(*.*)|*.*“;
????????openFileDialog1.FilterIndex?=?2;
????????openFileDialog1.RestoreDirectory?=?true;
????????if?(openFileDialog1.ShowDialog()?==?DialogResult.OK)
????????{
????????????MyFile?=?openFileDialog1.FileName;
????????????MyFileExt?=?MyFile.Substring(MyFile.LastIndexOf(“.“)?+?1);?//擴展名
????????}
????}
????//把圖像byte讀出,base64編碼寫入xml相應字段就可以了。
????private?void?button2_Click(object?sender?System.EventArgs?e)
????//圖形轉化成二進制存入xml
????{
????????if?(MyFile?==?““)
????????{
????????????MessageBox.Show(“請選擇一個圖片!“?“錯誤“
????????????????MessageBoxButtons.OK?MessageBoxIcon.Warning);
????????????return;
????????}
????????Image?MyImg?=?Image.FromFile(MyFile);
????????MemoryStream?memoryStream?=?new?MemoryStream();
????????MyImg.Save(memoryStream?GetImageType(MyFileExt));?//將圖像以指定格式保存到流中
????????byte[]?b;
????????b?=?memoryStream.GetBuffer();
????????string?pic?=?Convert.Tobase64String(b);
????????memoryStream.Close();
????????System.xml.xmlDocument?Myxml?=?new?System.xml.xmlDocument();
????????//字符串形式加載xml
????????Myxml.Loadxml(““?+?MyFile?+?“ “?+?pic?+?“ “);
????????Myxml.Save(“c:\\MyPhoto.xml“);
????????MessageBox.Show(“文件被保存到了:“?+?“c:\\MyPhoto.xml“);
????}
????private?void?button3_Click(object?sender?System.EventArgs?e)
????{
????????string?pic;
????????System.xml.xmlDocument?Myxml?=?new?System.xml.xmlDocument();
????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3787??2008-08-01?18:53??26.圖片和xm
?????文件???????4056??2008-08-01?18:43??26.圖片和xm
?????文件???????5814??2008-08-01?18:43??26.圖片和xm
?????文件????????483??2008-08-01?18:38??26.圖片和xm
?????文件???????3255??2008-08-01?18:55??26.圖片和xm
?????文件????????936??2008-08-01?18:55??26.圖片和xm
????..A..H.?????12288??2008-08-01?18:55??26.圖片和xm
?????文件???????5632??2005-11-11?22:25??26.圖片和xm
?????文件??????24576??2008-08-01?18:53??26.圖片和xm
?????文件??????26112??2008-08-01?18:53??26.圖片和xm
?????文件?????????80??2008-08-01?18:55??26.圖片和xm
?????文件????????180??2008-08-01?18:43??26.圖片和xm
?????文件????????180??2008-08-01?18:40??26.圖片和xm
?????文件??????26112??2008-08-01?18:53??26.圖片和xm
?????文件??????24576??2008-08-01?18:53??26.圖片和xm
?????文件????????842??2008-08-01?18:43??26.圖片和xm
?????文件???????1220??2008-08-01?18:38??26.圖片和xm
?????文件???????5612??2008-08-01?18:38??26.圖片和xm
?????文件???????2902??2008-08-01?18:38??26.圖片和xm
?????文件????????249??2008-08-01?18:38??26.圖片和xm
?????文件???????1107??2008-08-01?18:38??26.圖片和xm
?????目錄??????????0??2008-08-22?21:53??26.圖片和xm
?????目錄??????????0??2008-08-22?21:53??26.圖片和xm
?????目錄??????????0??2008-08-22?21:53??26.圖片和xm
?????目錄??????????0??2008-08-22?21:53??26.圖片和xm
?????目錄??????????0??2008-08-22?21:53??26.圖片和xm
?????目錄??????????0??2008-08-22?21:53??26.圖片和xm
?????目錄??????????0??2008-08-22?21:53??26.圖片和xm
?????目錄??????????0??2008-08-22?21:53??26.圖片和xm
?????目錄??????????0??2008-08-22?21:53??26.圖片和xm
............此處省略3個文件信息
- 上一篇:基于OPENGL的光線跟蹤源代碼368758
- 下一篇:用矩陣類算法程序和最小二乘法
評論
共有 條評論