qq_41856779
qq_41856779
采纳率0%
2018-03-17 13:34 阅读 4.7k

jpg格式的图片如何转换成xml文件

40

详细问题如下,JPG图片如何转换成大智慧软件股票池的xml文件,或者说是图片如何嵌入股票池的XML文件,软件又可以读取到图片。即图片在股票池文件中显示

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

8条回答 默认 最新

  • weixin_29057563 weixin_29057563 2018-03-17 13:38

    图片和XML格式文件相互转换

    Public Class Form1
    Private MyFile As String = ""
    Private MyFileExt As String = ""
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button1.Click
    '将图片保存成XML
    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.ToBase64String(b)
    memoryStream.Close()
    Dim MyXml As System.Xml.XmlDocument = New System.Xml.XmlDocument()
    MyXml.LoadXml("孟宪会" + pic + "")
    MyXml.Save("c:/MyPhoto.xml")
    Label1.Text = "文件被保存到了:" + Microsoft.VisualBasic.ChrW(13) + "c:/MyPhoto.xml"
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button2.Click
    '从XML中得到图片
    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 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
    

    End Class

    点赞 1 评论 复制链接分享
  • qq_29002107 qq_29002107 2018-03-17 17:05

    最简单的办法打开我的电脑——工具—— 隐藏已知文件扩展名点下确定OK。看你需要改的文件名后面有个.JPG改成.xml 完工

    点赞 评论 复制链接分享
  • y1150497974 y1150497974 2018-03-17 17:49

    对啊,有在线转的工具可以使用

    点赞 评论 复制链接分享
  • qq_21498657 qq_21498657 2018-03-17 18:07

    这个好像不可以吧,改后缀真是太搞笑了

    点赞 评论 复制链接分享
  • trb397 trb397 2018-03-17 23:20

    可以把 图片保存成XML,又可以把保存成XML的图片还原成图片

    点赞 评论 复制链接分享
  • caraway1425 caraway1425 2018-03-18 01:48

    直接改后缀应该可以的吧

    点赞 评论 复制链接分享
  • ikmcc ikmcc 2018-03-18 03:45

    百度在线修改,也可以下载软件修改。最直接的修改文件后缀名。

    点赞 评论 复制链接分享
  • weixin_35921874 a_shuan 2018-03-18 05:11

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Xml;
    using System.IO;
    using System.Drawing.Imaging;

    namespace xmlfile
    {
    ///
    /// aboatfile 的摘要说明。
    ///
    public class xmlfile
    {
    public xmlfile()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }
    //找开一幅XML图片(XmlTextReader)
    public Image openxmlfile(string xmlfilepath)
    {
    XmlTextReader readxml=new XmlTextReader(xmlfilepath);
    int len=64*1024;
    byte[] bytebmp=new byte [len];
    while (readxml.Read())
    {
    if (readxml.NodeType==XmlNodeType.Element)
    {
    if (readxml.LocalName.Equals("image"))
    {
    readxml.ReadBase64(bytebmp,0,len);
    }
    }
    }
    readxml.Close();
    readxml=null;
    FileStream streamfile=File.OpenWrite(@"C:Documents and SettingsAdministratorLocal SettingsTempa.bmp");
    streamfile.Write(bytebmp,0,bytebmp.Length);
    streamfile.Close();
    streamfile=null;
    Image img;
    img=System.Drawing.Bitmap.FromFile(@"C:Documents and SettingsAdministratorLocal SettingsTempa.bmp");
    return img;
    }
    //保存一幅XML图片(XmlTextWriter)
    public void savexmlfile(string xmlname)
    {
    FileStream fs=new FileStream(@"C:a.bmp",FileMode.Open);
    string time=DateTime.Now.ToLongDateString();
    int len=4029;
    int readByte=0;
    byte[] imgdata = new byte[len];
    XmlTextWriter xw=new XmlTextWriter(xmlname,System.Text.Encoding.UTF8);
    xw.WriteStartDocument();
    xw.WriteComment("XML图片,用base64储存创建于"+time);
    xw.WriteStartElement("image");
    BinaryReader br = new BinaryReader(fs);
    do
    {
    readByte=br.Read(imgdata, 0, len);
    xw.WriteBase64(imgdata, 0, readByte);
    }
    while (len <= readByte );
    xw.WriteEndElement();
    xw.WriteEndDocument();
    fs.Close();
    xw.Flush();
    xw.Close();
    File.Delete(@"C:a.bmp");
    }
    }
    }

    点赞 评论 复制链接分享

相关推荐