• 数码图像文件包含确定图像特征的元数据


    数码图像文件包含确定图像特征的元数据。例如相机品牌和型号。GDI+将单独的元数据段存储在PropertyItem对象中。可读取Image对象的PropertyItems属性以便从某个文件中检索所有的元数据。返回一个PropertyItem对象的数组,具有以下4个属性:Id、Value、Len和Type。Id是用于标识元数据项的标记。表9-1显示一些可赋予Id的值。这里无法插入表,例如0x0320图像标题,0x010F设备厂商,0x0110相机型号,0x829A曝光时间,0x5090亮度表,0x5091色度表等。Value是数组值。这些值的格式由Type属性确定。Len是Value属性指向的值的数组长度(以字节表示)。Type是Value属性指向的数组中值的数据类型。详细说明见C#编程指南清华出版社2011年1月出版。

    一个风景照实例,名为IMG_0445.jpg。读取并显示图片文件中的元数据。该列表中的第一个(index 0)属性项包含Id 0x010F(设备制造商)和Type 2(ASCII编码的字节数组)。代码示例显示该属性项的值。第二项表示设备型号。程序输出类似以下内容。

    Property item 0

    iD:0x10F

    type:2

    length:6 bytes

    Property item 1

    iD:0x110

    The equipement makes is Canon PowerShot A570 IS

    下面的示例在窗体上显示图像和图像的元数据。

    Image image = new Bitmap(@"..\..\IMG_0445.jpg");     //产生图像对象

    e.Graphics.DrawImage(image, 150, 10, 450, 310);       //显示图像

    PropertyItem[] propItems = image.PropertyItems;       //得到图像PropertyItems数组

    Font font = new Font("Arial", 12);                    //设置字体

    SolidBrush blackBrush = new SolidBrush(Color.Black);

    int X = 0;

    int Y = 0;

    int count = 0;

    //对数组中的每一个PropertyItem属性项,显示ID和长度

    foreach (PropertyItem propItem in propItems)

    {

      e.Graphics.DrawString( "Property Item " + count.ToString(),font, blackBrush, X, Y);

      Y += font.Height;

      e.Graphics.DrawString( "   iD: 0x" + propItem.Id.ToString("x"), font, blackBrush, X, Y);

      Y += font.Height;

      e.Graphics.DrawString( "   type: " + propItem.Type.ToString(), font, blackBrush, X, Y);

      Y += font.Height;

      e.Graphics.DrawString( "   length: "+propItem.Len.ToString() + " bytes", font, blackBrush,X,Y);

      Y += font.Height;

      count++;

    }

    //变换第2个属性值为字符串并显示.

    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

    string manufacturer = encoding.GetString(propItems[1].Value);

    e.Graphics.DrawString( "The equipment make is " + manufacturer + ".", font, blackBrush, 150, 350);

    输出如图所示,照片下方显示相机是Canon PowerShot A570 IS(佳能相机)

    提问者评价
    谢谢你的帮助
  • 相关阅读:
    小白逆袭的真实故事,句句干货不看损失一个亿!
    CODEFORCES 1367F2 FLYING SORT (HARD VERSION)
    整理:iOS开发知识点
    EBS-子库存转移和物料搬运单区别
    Oracle ERP系統借贷关系表
    ORACLE ERP各模块会计分录
    SQL Queries and Multi-Org Architecture in Release 12
    ORALCE EBS ALERT 初体验
    工作流邮件审批设置
    How to Send an Email Using UTL_SMTP with Authenticated Mail Server
  • 原文地址:https://www.cnblogs.com/xianyin05/p/3075721.html
Copyright © 2020-2023  润新知