zoukankan      html  css  js  c++  java
  • .NET : 如何读取图片中的元数据信息

    如果我们希望在程序中对图片中包含的一些元数据信息进行读取,并作为后期分析的准备。那么可以参考下面这个例子

    http://www.codeproject.com/KB/graphics/photoproperties.aspx

    我在这基础上也做了一个范例,如下图的效果

    image

    代码大致如下

    private void btSelectImageFile_Click(object sender, EventArgs e)
    {
        OpenFileDialog dialog = new OpenFileDialog();
        dialog.Filter = "Image File (*.jpg)|*.jpg";
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            pbImage.Image = Image.FromFile(dialog.FileName);

            JSG.PhotoPropertiesLibrary.PhotoProperties p = new JSG.PhotoPropertiesLibrary.PhotoProperties();
            p.Initialize();
            p.Analyze(dialog.FileName);
            JSG.PhotoPropertiesLibrary.ResultOptions options = new JSG.PhotoPropertiesLibrary.ResultOptions();

            MemoryStream ms = new MemoryStream();
            p.WriteXml(ms, options);
            if (ms.CanRead == false)
            {
                byte[] buffer = ms.GetBuffer();
                ms = new MemoryStream(buffer);
            }

            XDocument doc = XDocument.Load(new XmlTextReader(ms), LoadOptions.PreserveWhitespace);

            var query = from x in doc.Descendants("tagDatum")
                        select new
                           {
                               Id = x.Attribute("id").Value,
                               Category = x.Attribute("category").Value,
                               Name = x.Element("name").Value,
                               Description = x.Element("description").Value,
                               Value = x.Element("value").Value
                           };

            dgvProperties.DataSource = query.ToArray();

        }
    }

  • 相关阅读:
    Convolution1D与Convolution2D区别
    git
    cast函数
    Ubuntu14.04编译WebRTC For Android代码 2014-07-24
    R语言基础-数组和列表
    疯狂的创业运动
    Autodesk 举办的 Revit 2015 二次开发速成( 1.5 天),教室培训, 地点武汉
    注冊(十一)重注冊带有鉴权信息
    ubuntu14.04无法安装Curl
    Bash脚本中的操作符
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1608568.html
Copyright © 2011-2022 走看看