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();

        }
    }

  • 相关阅读:
    Bzoj 1537: [POI2005]Aut- The Bus 题解 [由暴力到正解]
    Bzoj 3126[Usaco2013 Open]Photo 题解
    Bzoj 3165 [Heoi2013]Segment题解
    Bzoj 2733: [HNOI2012]永无乡 数组Splay+启发式合并
    赛前集训前的总结(警醒)
    bzoj3316 JC loves Mkk题解
    9.22考试 crf的军训 题解
    Luogu3521 [POI2011]ROT-Tree Rotations
    CTSC2012 熟悉的文章
    UVA11468 Substring
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1608568.html
Copyright © 2011-2022 走看看