Convert image files to XML format files The FromBase64String and ToBase64String methods under the .NET framework can easily implement the interchange of image files and XML files. This can easily solve the problem of saving pictures in XML format. The code is as follows: Public Class Form1
Inherits #Region " Code generated by Windows Forms Designer"
Public Sub New()
()
InitializeComponent()
Add any initialization after the InitializeComponent() call
End Sub Form rewrite disposal to clean up component lists.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
()
End If
End If
(disposing)
End Sub Required for Windows Forms Designer
Private components As
Note: The following procedure is required for Windows Form Designer
This process can be modified using the Windows Form Designer.
Do not modify it using a code editor.
Friend WithEvents Button1 As
Friend WithEvents Button2 As
Friend WithEvents PictureBox1 As
Friend WithEvents Button3 As
Friend WithEvents Label1 As
Friend WithEvents Label2 As
<()> Private Sub InitializeComponent()
Me.Button1 = New ()
Me.Button2 = New ()
Me.PictureBox1 = New ()
Me.Button3 = New ()
Me.Label1 = New ()
Me.Label2 = New ()
()
Button1
Me. = New (365, 63)
Me. = "Button1"
Me. = New (115, 23)
Me. = 0
Me. = "Save the image as XML"
Button2
Me. = New (365, 98)
Me. = "Button2"
Me. = New (115, 23)
Me. = 1
Me. = "Get image from XML"
PictureBox1
Me. = New (18, 6)
Me. = "PictureBox1"
Me. = New (320, 460)
Me. = 2
Me. = False
Button3
Me. = New (365, 28)
Me. = "Button3"
Me. = New (115, 23)
Me. = 3
Me. = "Browse pictures..."
Label1
Me. = New (369, 135)
Me. = "Label1"
Me. = New (105, 95)
Me. = 4
Label2
Me. = New (367, 437)
Me. = "Label2"
Me. = New (130, 16)
Me. = 5
Me. = "【Meng Xianhui’s Wonderful World】"
Form1
= New (5, 13)
= New (500, 480)
(New () {Me.Label2, Me.Label1, _
Me.Button3, Me.PictureBox1, Me.Button2, Me.Button1})
= "Form1"
= "Example of interchangeable image files and XML format files"
(False) End Sub #End Region Private MyFile As String = ""
Private MyFileExt As String = ""
Private Sub Button2_Click(ByVal sender As , ByVal e As ) _
Handles
Dim pic As String
Dim MyXml As = New ()
("c:\")
Dim picNode As
picNode = ("/pic/photo")
pic =
Dim memoryStream As
memoryStream = New (Convert.FromBase64String(pic))
Me. = New (memoryStream)
()
End Sub Private Sub Button1_Click(ByVal sender As , ByVal e As ) _
Handles
If MyFile = "" Then
("Please select a picture!", "Error", , )
Exit Sub
End If
Dim MyImg As = (MyFile)
Dim memoryStream As = New ()
(memoryStream, GetImageType(MyFileExt))
Dim b() As Byte
b = ()
Dim pic As String = Convert.ToBase64String(b)
()
Dim MyXml As = New ()
("<pic><name>Meng Xianhui</name><photo>" + pic + "</photo></pic>")
("c:\")
= "The file was saved to: " + (13) + "c:\"
End Sub Private Sub Button3_Click(ByVal sender As , ByVal e As ) _
Handles
Dim openFileDialog1 As New OpenFileDialog()
= "c:\"
= "PNG(*.png)|*.png|Gif(*.gif)|*.gif|Jpg(*.jpg)|*.jpg|All image files(*.*)|*.*"
= 2
= True
If () = Then
MyFile = ()
MyFileExt = ((".") + 1)
End If
End Sub Public Function GetImageType(ByVal str As String) As
Select Case ()
Case "jpg"
Return
Case "gif"
Return
Case "tiff"
Return ()
Case "icon"
Return
Case "image/png"
Return
Case Else
Return
End Select
End Function Private Sub Form1_Closing(ByVal sender As Object, ByVal e As ) _
Handles
("", "/")
End Sub
End Class