이미지 파일 을 XML 형식 파일 로 변환 합 니 다.

이미지 파일 을 XML 형식 파일 로 변환 합 니 다.
.NET 프레임 워 크 의 FromBase64String 과 ToBase64String 방법 을 이용 하면 이미지 파일 과 XML 파일 의 교환 을 쉽게 실현 할 수 있다.이렇게 하면 XML 형식 으로 그림 을 저장 하 는 문 제 를 쉽게 해결 할 수 있다.코드 는 다음 과 같 습 니 다:
Public Class Form1 Inherits System.Windows.Forms.Form
\#Region"Windows 창 디자이너 가 만 든 코드"Public Sub New()MyBase.New()InitializeComponent()는 InitializeComponent()호출 후 초기 화 최종 Sub 를 추가 합 니 다.
구성 요소 목록 을 정리 하기 위해 창 을 다시 쓰 십시오.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 창 디자이너 에 필요 한 Private components As System.Component Model.IContainer 주의:다음 과정 은 Windows 창 디자이너 에 필요 한 Windows 창 디자이너 를 사용 하여 이 과정 을 수정 할 수 있 습 니 다.코드 편집기 로 수정 하지 마 세 요.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()Button 1 Me.Button 1.Location=New System.Drawing.Point(365,63)Me.Button 1.Name="Button 1"Me.Button 1.Size=New System.Drawing.size(115,23)Me.Button 1.TabIndex=0 Me.Button 1.Text="그림 을 XML 로 저장 합 니 다"Button 2 Me.Button 2.Location=New System.Drawing.Point(365,)98)Me.Button 2.Name="Button 2"Me.Button 2.Size=New System.Drawing.size(115,23)Me.Button 2.TabIndex=1 Me.Button 2.Text="XML 에서 이미지 얻 기"PictureBox 1 Me.PictureBox 1.Location=New System.Drawing.Point(18,6)Me.PictureBox 1.Name="PictureBox 1"Me.PictureBox 1.Size=New System.Drawing.size(320,320,6)460)Me.PictureBox 1.TabIndex=2 Me.PictureBox 1.TabStop=False Button 3 Me.Button 3.Location=New System.Drawing.Point(365,28)Me.Button 3.Name="Button 3"Me.Button 3.Size=New System.Drawing.size(115,23)Me.Button 3.TabIndex=3 Me.Button 3.Text="그림 탐색..."Label 1 Me.Label 1.Location=New System.Drawing.Point(369,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="[맹 헌 회의 멋 진 세상]"Form1 Me.AutoScaleBaseSize=New System.Trawing.size(5,13)Me.ClientSize=New System.Trawing.size(500,480)Me.Control.AddRange(New System.Windows.Forms.Control(){Me.Label 2,Me.Label 1,Me.Button 3,Me.PictureBox 1,Me.Button 2,Me.Button 1})Me.Name="Form 1"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("그림 을 선택 하 십시오!","오류",MessageBoxButtons.OK,MessageBoxIcon.Warning)종료 서브 엔 드 Dim MyImg As System.Drawing.Image=MyImg.FromFile(MyFile)Dim memory Stream As System.IO.Memory Stream=New System.IO.Memory Stream()MyImg.save(memory Stream,(MyFileExt)Dim b()As Byte b=memory Stream.GetBuffer()Dim pic As String=Convert.ToBase64String(b)memory Stream.Close()Dim MyXml AsSystem.Xml.XmlDocument=New System.Xml.XmlDocument()MyXml.XmlDocDocument()MyXml.LodXml(<맹 헌 회>>>>>>>>>>>>>/pic>>)MyXml.save("c:\\MyPhoto.xml"xml")MyXml.save("c:\\\\MyPhoto.xml"xml").xml)MyXml.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) _ 새 OpenFileDialog()openFileDialog 1.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) 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

좋은 웹페이지 즐겨찾기