麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 開(kāi)發(fā) > XML > 正文

如何把圖象文件轉(zhuǎn)換成XML格式文件

2024-09-05 20:55:15
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友


把圖象文件轉(zhuǎn)換成XML格式文件 利用.NET 框架下的FromBase64String和ToBase64String方法可以很容易地實(shí)現(xiàn)圖象文件和XML文件的互換。這樣可以輕易解決以XML格式保存圖片的問(wèn)題。代碼如下: Public Class Form1
Inherits System.Windows.Forms.Form #Region " Windows 窗體設(shè)計(jì)器生成的代碼 "
Public Sub New()
MyBase.New()
InitializeComponent()
在 InitializeComponent() 調(diào)用之后添加任何初始化
End Sub 窗體重寫(xiě)處置以清理組件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub Windows 窗體設(shè)計(jì)器所必需的
Private components As System.ComponentModel.IContainer
注意:以下過(guò)程是 Windows 窗體設(shè)計(jì)器所必需的
可以使用 Windows 窗體設(shè)計(jì)器修改此過(guò)程。
不要使用代碼編輯器修改它。
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.Button3 = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.SuspendLayout()

Button1

Me.Button1.Location = New System.Drawing.Point(365, 63)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(115, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "將圖象保存成XML"

Button2

Me.Button2.Location = New System.Drawing.Point(365, 98)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(115, 23)
Me.Button2.TabIndex = 1
Me.Button2.Text = "從XML中得到圖象"

PictureBox1

Me.PictureBox1.Location = New System.Drawing.Point(18, 6)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(320, 460)
Me.PictureBox1.TabIndex = 2
Me.PictureBox1.TabStop = False

Button3

Me.Button3.Location = New System.Drawing.Point(365, 28)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(115, 23)
Me.Button3.TabIndex = 3
Me.Button3.Text = "瀏覽圖片…"

Label1

Me.Label1.Location = New System.Drawing.Point(369, 135)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(105, 95)
Me.Label1.TabIndex = 4

Label2

Me.Label2.Location = New System.Drawing.Point(367, 437)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(130, 16)
Me.Label2.TabIndex = 5
Me.Label2.Text = "【孟憲會(huì)之精彩世界】"

Form1

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(500, 480)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label2, Me.Label1, _
Me.Button3, Me.PictureBox1, Me.Button2, Me.Button1})
Me.Name = "Form1"
Me.Text = "圖象文件和XML格式文件互換例子"
Me.ResumeLayout(False) End Sub #End Region Private MyFile As String = ""
Private MyFileExt As String = ""
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button2.Click
Dim pic As String
Dim MyXml As System.Xml.XmlDocument = New System.Xml.XmlDocument()
MyXml.Load("c:/MyPhoto.xml")
Dim picNode As System.Xml.XmlNode
picNode = MyXml.SelectSingleNode("/pic/photo")
pic = picNode.InnerText
Dim memoryStream As System.IO.MemoryStream
memoryStream = New System.IO.MemoryStream(Convert.FromBase64String(pic))
Me.PictureBox1.Image = New System.Drawing.Bitmap(memoryStream)
memoryStream.Close()
End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
If MyFile = "" Then
MessageBox.Show("請(qǐng)選擇一個(gè)圖片!", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
Dim MyImg As System.Drawing.Image = MyImg.FromFile(MyFile)
Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream()
MyImg.Save(memoryStream, GetImageType(MyFileExt))
Dim b() As Byte
b = memoryStream.GetBuffer()
Dim pic As String = Convert.ToBase64String(b)
memoryStream.Close()
Dim MyXml As System.Xml.XmlDocument = New System.Xml.XmlDocument()
MyXml.LoadXml("孟憲會(huì)" + pic + "")
MyXml.Save("c:/MyPhoto.xml")
Label1.Text = "文件被保存到了:" + Microsoft.VisualBasic.ChrW(13) + "c:/MyPhoto.xml"
End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button3.Click
Dim openFileDialog1 As 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 Then
MyFile = openFileDialog1.FileName()
MyFileExt = MyFile.Substring(MyFile.LastIndexOf(".") + 1)
End If
End Sub Public Function GetImageType(ByVal str As String) As System.Drawing.Imaging.ImageFormat
Select Case str.ToLower()
Case "jpg"
Return System.Drawing.Imaging.ImageFormat.Jpeg
Case "gif"
Return System.Drawing.Imaging.ImageFormat.Gif
Case "tiff"
Return System.Drawing.Imaging.ImageFormat.Tiff()
Case "icon"
Return System.Drawing.Imaging.ImageFormat.Icon
Case "image/png"
Return System.Drawing.Imaging.ImageFormat.Png
Case Else
Return System.Drawing.Imaging.ImageFormat.MemoryBmp
End Select
End Function Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
System.Diagnostics.Process.Start("IExplore.exe", "http://xml.sz.luohuedu.net/")
End Sub
End Class

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 精品一区二区免费 | 蜜桃视频在线观看视频 | 日韩精品久久久 | 色蜜桃av| 久久第四色| 欧美成人午夜精品久久久 | 九九精品在线观看视频 | 久久精品国产99国产精品澳门 | 久草在线视频首页 | 久久精品一级片 | 国产成年人在线观看 | 91 在线| 国产成年人网站 | 精品国产一区二区三区在线观看 | 一级电影在线观看 | 国产一精品久久99无吗一高潮 | 国产又白又嫩又紧又爽18p | jizzjizzjizzjizz国产| 性盈盈盈影院 | 国产精品亚洲精品久久 | 羞羞草视频 | 91色琪琪电影亚洲精品久久 | 久久国产精 | 久久蜜桃香蕉精品一区二区三区 | 全免费午夜一级毛片真人 | 欧美精品成人一区二区三区四区 | 欧美成人性色 | 午夜国产在线 | 国产精品久久久久久久久久 | 日韩视频一区二区 | 中国av中文字幕 | av在线不卡免费 | 手机免费看一级片 | 91精品国产综合久久久欧美 | 黄色a级片免费观看 | 黄色二区三区 | 日韩色电影 | 高清在线观看av | 国产精品99久久久久久久 | h视频免费在线观看 | 97精品国产高清在线看入口 |