知识大全 把图象文件转换成XML格式文件

Posted

篇首语:从来好事天生俭,自古瓜儿苦后甜。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 把图象文件转换成XML格式文件相关的知识,希望对你有一定的参考价值。

把图象文件转换成XML格式文件  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

利用 NET 框架下的FromBase String和ToBase String方法可以很容易地实现图象文件和XML文件的互换 这样可以轻易解决以XML格式保存图片的问题 代码如下   Public Class Form   Inherits System Windows Forms Form  #Region Windows 窗体设计器生成的代码   Public Sub New()  MyBase New()  InitializeComponent()  在 InitializeComponent() 调用之后添加任何初始化  End Sub  窗体重写处置以清理组件列表   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)  If disposing Then  If Not (ponents Is Nothing) Then  ponents Dispose()  End If  End If  MyBase Dispose(disposing)  End Sub  Windows 窗体设计器所必需的  Private ponents As System ComponentModel IContainer  注意 以下过程是 Windows 窗体设计器所必需的  可以使用 Windows 窗体设计器修改此过程   不要使用代码编辑器修改它   Friend WithEvents Button As System Windows Forms Button  Friend WithEvents Button As System Windows Forms Button  Friend WithEvents PictureBox As System Windows Forms PictureBox  Friend WithEvents Button As System Windows Forms Button  Friend WithEvents Label As System Windows Forms Label  Friend WithEvents Label As System Windows Forms Label  <System Diagnostics DebuggerStepThrough()> Private Sub InitializeComponent()  Me Button = New System Windows Forms Button()  Me Button = New System Windows Forms Button()  Me PictureBox = New System Windows Forms PictureBox()  Me Button = New System Windows Forms Button()  Me Label = New System Windows Forms Label()  Me Label = New System Windows Forms Label()  Me SuspendLayout()    Button     Me Button Location = New System Drawing Point( )  Me Button Name = Button   Me Button Size = New System Drawing Size( )  Me Button TabIndex =   Me Button Text = 将图象保存成XML     Button     Me Button Location = New System Drawing Point( )  Me Button Name = Button   Me Button Size = New System Drawing Size( )  Me Button TabIndex =   Me Button Text = 从XML中得到图象     PictureBox     Me PictureBox Location = New System Drawing Point( )  Me PictureBox Name = PictureBox   Me PictureBox Size = New System Drawing Size( )  Me PictureBox TabIndex =   Me PictureBox TabStop = False    Button     Me Button Location = New System Drawing Point( )  Me Button Name = Button   Me Button Size = New System Drawing Size( )  Me Button TabIndex =   Me Button Text = 浏览图片…     Label     Me Label Location = New System Drawing Point( )  Me Label Name = Label   Me Label Size = New System Drawing Size( )  Me Label TabIndex =     Label     Me Label Location = New System Drawing Point( )  Me Label Name = Label   Me Label Size = New System Drawing Size( )  Me Label TabIndex =   Me Label Text = 【孟宪会之精彩世界】     Form     Me AutoScaleBaseSize = New System Drawing Size( )  Me ClientSize = New System Drawing Size( )  Me Controls AddRange(New System Windows Forms Control() Me Label Me Label Me Button Me PictureBox Me Button Me Button )  Me Name = Form   Me Text = 图象文件和XML格式文件互换例子   Me ResumeLayout(False)  End Sub  #End Region  Private MyFile As String =   Private MyFileExt As String =   Private Sub Button _Click(ByVal sender As System Object ByVal e As System EventArgs) _  Handles Button 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 FromBase String(pic))  Me PictureBox Image = New System Drawing Bitmap(memoryStream)  memoryStream Close()  End Sub  Private Sub Button _Click(ByVal sender As System Object ByVal e As System EventArgs) _  Handles Button Click  If MyFile = Then  MessageBox Show( 请选择一个图片! 错误 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 ToBase String(b)  memoryStream Close()  Dim MyXml As System Xml XmlDocument = New System Xml XmlDocument()  MyXml LoadXml( <pic><name>孟宪会</name><photo> + pic + </photo></pic> )  MyXml Save( c:\\MyPhoto xml )  Label Text = 文件被保存到了 + Microsoft VisualBasic ChrW( ) + c:\\MyPhoto xml   End Sub  Private Sub Button _Click(ByVal sender As System Object ByVal e As System EventArgs) _  Handles Button Click  Dim openFileDialog As New OpenFileDialog()  openFileDialog InitialDirectory = c:\\   openFileDialog Filter = PNG(* png)|* png|Gif(* gif)|* gif|Jpg(* jpg)|* jpg|所有图象文件(* *)|* *   openFileDialog FilterIndex =   openFileDialog RestoreDirectory = True  If openFileDialog ShowDialog() = DialogResult OK Then  MyFile = openFileDialog FileName()  MyFileExt = MyFile Substring(MyFile LastIndexOf( ) + )  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 Form _Closing(ByVal sender As Object ByVal e As System ComponentModel CancelEventArgs) _  Handles MyBase Closing  System Diagnostics Process Start( IExplore exe )  End Sub  End Class cha138/Article/program/net/201311/11970

相关参考

知识大全 Word. excel. ppt. 分别可以转换成哪些格式文件

Word.excel.ppt.分别可以转换成哪些格式文件?尽量全面。谢谢!  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我

知识大全 x4的图片能转换成jpg格式吗?请回答具体一些,谢谢

coreldrawx4的图片能转换成jpg格式吗?请回答具体一些,谢谢!可以。文件>导出,选择jpg格式就可以了。怎么把jpg格式的图片转换成gft格式的图片知道的回答下谢谢了用格式工厂,轻松转

知识大全 怎么把图片转换为.ico图标文件?

怎么把图片转换为.ico图标文件?制作方法一,打开ps,直接新建ctrt+N,新建高宽为256像素大小的图像,(本人亲测,当高宽任一大于256像素的话,保存时都不能为ico格式),控制高宽像素小于25

知识大全 C#转换图片文件格式

C#转换图片文件格式  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  将图片转换为另一种格式的图像

知识大全 如何把扫描文件变成电子文件

如何把扫描文件变成电子文件?想要转换必须安装相关软件,ocr软件,可以用百度进行搜索下载解决方案如下:扫描仪安装的时候要完全安装,通过OCR软件把纸质文件转换成电子的word如何把纸上的文件变成电子文

知识大全 手机里的音频文件一般是什么格式

手机里的音频文件一般是什么格式去appstore找找看,有免费的转换器。用酷狗推荐你用格式工厂这个款软件,很不错的,音频、视频、图片都可以转换。文件可以也可以任意选择。做铃声的音频文件一般什么格式.分

知识大全 spring中读取xml配置文件、获取bean

  读取xml文件  /**  *利用XmlBeanFactory(Resourceresource)  *这里Resource必须是xml格式  *Resource包括AbstractResourc

知识大全 java中如何把图片转换成二进制流

   将Image图像文件存入到数据库中我们知道数据库里的Image类型的数据是二进制数据因此必须将图像文件转换成字节数组才能存入数据库中  &nbs

知识大全 nvarchar和varchar的转换问题

  java编程将表中的nvarchar记录导出存储到xml文件中利用xdk的函数导出后发现xml文件中存储的表中的nvarchar字段中的中文变成了二进制码再将xml文件导入时报错所以我想将nvar

知识大全 在酷狗中怎么才能把格式改成mp3的

在酷狗中怎么才能把格式改成mp3的1、选定歌曲:在需要操作的歌曲上(注意只有在播放列表中),点击鼠标右键,选择“格式转换”,弹出“格式转换工具”窗口或者从开始菜单中的酷狗音乐文件夹中选取格式转换工具,