日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
VB.NET實現(xiàn)圖象文件和XML文件互換

通過.NET框架下的FromBase64String和ToBase64String方法可以很容易地實現(xiàn)圖象文件和XML文件的互換。這樣可以輕易解決以XML格式保存圖片的問題。以下是利用VB.NET實現(xiàn)圖象文件和XML文件的互換代碼:

10多年的林周網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。營銷型網(wǎng)站的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整林周建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)公司從事“林周網(wǎng)站設(shè)計”,“林周網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。

 
 
 
  1. Public Class Form1
  2. Inherits System.Windows.Forms.Form
  3. #Region " Windows 窗體設(shè)計器生成的代碼 "
  4. Public Sub New()
  5. MyBase.New()
  6. InitializeComponent()
  7. 在 InitializeComponent() 調(diào)用之后添加任何初始化
  8. End Sub
  9. 窗體重寫處置以清理組件列表。
  10. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  11. If disposing Then
  12. If Not (components Is Nothing) Then
  13. components.Dispose()
  14. End If
  15. End If
  16. MyBase.Dispose(disposing)
  17. End Sub
  18. Windows 窗體設(shè)計器所必需的
  19. Private components As System.ComponentModel.IContainer
  20. 注意:以下過程是 Windows 窗體設(shè)計器所必需的
  21. 可以使用 Windows 窗體設(shè)計器修改此過程。
  22. 不要使用代碼編輯器修改它。
  23. Friend WithEvents Button1 As System.Windows.Forms.Button
  24. Friend WithEvents Button2 As System.Windows.Forms.Button
  25. Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
  26. Friend WithEvents Button3 As System.Windows.Forms.Button
  27. Friend WithEvents Label1 As System.Windows.Forms.Label
  28. Friend WithEvents Label2 As System.Windows.Forms.Label
  29.  Private Sub InitializeComponent()
  30. Me.Button1 = New System.Windows.Forms.Button()
  31. Me.Button2 = New System.Windows.Forms.Button()
  32. Me.PictureBox1 = New System.Windows.Forms.PictureBox()
  33. Me.Button3 = New System.Windows.Forms.Button()
  34. Me.Label1 = New System.Windows.Forms.Label()
  35. Me.Label2 = New System.Windows.Forms.Label()
  36. Me.SuspendLayout()
  37. Button1
  38. Me.Button1.Location = New System.Drawing.Point(365, 63)
  39. Me.Button1.Name = "Button1"
  40. Me.Button1.Size = New System.Drawing.Size(115, 23)
  41. Me.Button1.TabIndex = 0
  42. Me.Button1.Text = "將圖象保存成XML"
  43. Button2
  44. Me.Button2.Location = New System.Drawing.Point(365, 98)
  45. Me.Button2.Name = "Button2"
  46. Me.Button2.Size = New System.Drawing.Size(115, 23)
  47. Me.Button2.TabIndex = 1
  48. Me.Button2.Text = "從XML中得到圖象"
  49. PictureBox1
  50. Me.PictureBox1.Location = New System.Drawing.Point(18, 6)
  51. Me.PictureBox1.Name = "PictureBox1"
  52. Me.PictureBox1.Size = New System.Drawing.Size(320, 460)
  53. Me.PictureBox1.TabIndex = 2
  54. Me.PictureBox1.TabStop = False
  55. Button3
  56. Me.Button3.Location = New System.Drawing.Point(365, 28)
  57. Me.Button3.Name = "Button3"
  58. Me.Button3.Size = New System.Drawing.Size(115, 23)
  59. Me.Button3.TabIndex = 3
  60. Me.Button3.Text = "瀏覽圖片…"
  61. Label1
  62. Me.Label1.Location = New System.Drawing.Point(369, 135)
  63. Me.Label1.Name = "Label1"
  64. Me.Label1.Size = New System.Drawing.Size(105, 95)
  65. Me.Label1.TabIndex = 4
  66. Label2
  67. Me.Label2.Location = New System.Drawing.Point(367, 437)
  68. Me.Label2.Name = "Label2"
  69. Me.Label2.Size = New System.Drawing.Size(130, 16)
  70. Me.Label2.TabIndex = 5
  71. Me.Label2.Text = "【孟憲會之精彩世界】"
  72. Form1
  73. Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  74. Me.ClientSize = New System.Drawing.Size(500, 480)
  75. Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label2, Me.Label1, Me.Button3, Me.PictureBox1, Me.Button2, Me.Button1})
  76. Me.Name = "Form1"
  77. Me.Text = "圖象文件和XML格式文件互換例子"
  78. Me.ResumeLayout(False)
  79. End Sub
  80. #End Region
  81. Private MyFile As String = ""
  82. Private MyFileExt As String = ""
  83. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  84. Handles Button2.Click
  85. Dim pic As String
  86. Dim MyXml As System.Xml.XmlDocument = New System.Xml.XmlDocument()
  87. MyXml.Load("c:\MyPhoto.xml")
  88. Dim picNode As System.Xml.XmlNode
  89. picNode = MyXml.SelectSingleNode("/pic/photo")
  90. pic = picNode.InnerText
  91. Dim memoryStream As System.IO.MemoryStream
  92. memoryStream = New System.IO.MemoryStream(Convert.FromBase64String(pic))
  93. Me.PictureBox1.Image = New System.Drawing.Bitmap(memoryStream)
  94. memoryStream.Close()
  95. End Sub
  96. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  97. Handles Button1.Click
  98. If MyFile = "" Then
  99. MessageBox.Show("請選擇一個圖片!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  100. Exit Sub
  101. End If
  102. Dim MyImg As System.Drawing.Image = MyImg.FromFile(MyFile)
  103. Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream()
  104. MyImg.Save(memoryStream, GetImageType(MyFileExt))
  105. Dim b() As Byte
  106. b = memoryStream.GetBuffer()
  107. Dim pic As String = Convert.ToBase64String(b)
  108. memoryStream.Close()
  109. Dim MyXml As System.Xml.XmlDocument = New System.Xml.XmlDocument()
  110. MyXml.LoadXml("孟憲會" + pic + "")
  111. MyXml.Save("c:\MyPhoto.xml")
  112. Label1.Text = "文件被保存到了:" + Microsoft.VisualBasic.ChrW(13) + "c:\MyPhoto.xml"
  113. End Sub
  114. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  115. Handles Button3.Click
  116. Dim openFileDialog1 As New OpenFileDialog()
  117. openFileDialog1.InitialDirectory = "c:\"
  118. openFileDialog1.Filter = "PNG(*.png)|*.png|Gif(*.gif)|*.gif|Jpg(*.jpg)|*.jpg|所有圖象文件(*.*)|*.*"
  119. openFileDialog1.FilterIndex = 2
  120. openFileDialog1.RestoreDirectory = True
  121. If openFileDialog1.ShowDialog() = DialogResult.OK Then
  122. MyFile = openFileDialog1.FileName()
  123. MyFileExt = MyFile.Substring(MyFile.LastIndexOf(".") + 1)
  124. End If
  125. End Sub
  126. Public Function GetImageType(ByVal str As String) As System.Drawing.Imaging.ImageFormat
  127. Select Case str.ToLower()
  128. Case "jpg"
  129. Return System.Drawing.Imaging.ImageFormat.Jpeg
  130. Case "gif"
  131. Return System.Drawing.Imaging.ImageFormat.Gif
  132. Case "tiff"
  133. Return System.Drawing.Imaging.ImageFormat.Tiff()
  134. Case "icon"
  135. Return System.Drawing.Imaging.ImageFormat.Icon
  136. Case "image/png"
  137. Return System.Drawing.Imaging.ImageFormat.Png
  138. Case Else
  139. Return System.Drawing.Imaging.ImageFormat.MemoryBmp
  140. End Select
  141. End Function
  142. Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
  143. Handles MyBase.Closing
  144. System.Diagnostics.Process.Start("IExplore.exe", "http://xml.sz.luohuedu.net/")
  145. End Sub
  146. End Class

當(dāng)前文章:VB.NET實現(xiàn)圖象文件和XML文件互換
文章轉(zhuǎn)載:http://m.5511xx.com/article/dhspsjs.html