zoukankan      html  css  js  c++  java
  • 照片元数据信息以及在照片中写入gps信息

    /// 照片元数据编码
    在下面的文章里,可以看到图片所有的元数据定义信息
     
     
     元数据的结果类型定义
    /// 数据类型结果
     
    Integer表示的类型
    1 指定 Value 为字节数组。
    2 指定 Value 为空终止 ASCII 字符串。如果将类型数据成员设置为 ASCII 类型,则应该将 Len 属性设置为包括空终止的字符串长度。例如,字符串“Hello”的长度为 6。
    3 指定 Value 为无符号的短(16 位)整型数组。
    4 指定 Value 为无符号的长(32 位)整型数组。
    5 指定 Value 数据成员为无符号的长整型对数组。每一对都表示一个分数;第一个整数是分子,第二个整数是分母。
    6 指定 Value 为可以包含任何数据类型的值的字节数组。
    7 指定 Value 为有符号的长(32 位)整型数组。
    10 指定 Value 为有符号的长整型对数组。每一对都表示一个分数;第一个整数是分子,第二个整数是分母。
     
    操作元数据的一般步骤:
    1:读取图片得到Bitmap
    2:得到一个PropertyItem对象, PropertyItem propertyItem = image.PropertyItems[0];
    3:为该PropertyItem对象设置Id ,Value ,Type ,Len 等属性(查表看格式和Id)
    4:将值保存 image.SetPropertyItem(propertyItem);
    5:保存图片,就可以得到包含指定信息的图片文件了。
    不用担心覆盖的问题,不知道为啥微软不让创建PropertyItem对象,而通过这种方式,来为照片添加元数据信息。
    通过元数据,我们可以对照片进行很多后期处理,比如根据照相时间重新命名文件,给照片添加版权信息,添加描述等等信息。
     
     
     
    写入经纬度信息
               /// PropertyTagGpsLatitudeRef
                SetPropertyString(bitmap, 0x0001, "N");
                /// PropertyTagGpsLongitudeRef
                SetPropertyString(bitmap, 0x0003, "E");
                byte[] bytes = new byte[24];
                byte[] bytes1 = BitConverter.GetBytes(39);
                byte[] bytes2 = BitConverter.GetBytes(1);
                byte[] bytes3 = BitConverter.GetBytes(36);
                byte[] bytes4 = BitConverter.GetBytes(1);
                byte[] bytes5 = BitConverter.GetBytes(1256789553);
                byte[] bytes6 = BitConverter.GetBytes(10000000);
                int index = 0;
                bytes1.CopyTo(bytes, index);
                index += 4;
                bytes2.CopyTo(bytes, index);
                index += 4;
                bytes3.CopyTo(bytes, index);
                index += 4;
                bytes4.CopyTo(bytes, index);
                index += 4;
                bytes5.CopyTo(bytes, index);
                index += 4;
                bytes6.CopyTo(bytes, index);
    
                /// PropertyTagGpsLatitude
                SetProperty(bitmap, 0x0002, bytes, 5);
    
                bytes = new byte[24];
                bytes1 = BitConverter.GetBytes(116);
                bytes2 = BitConverter.GetBytes(1);
                bytes3 = BitConverter.GetBytes(21);
                bytes4 = BitConverter.GetBytes(1);
                bytes5 = BitConverter.GetBytes(2196657632);
                bytes6 = BitConverter.GetBytes(10000000);
                index = 0;
                bytes1.CopyTo(bytes, index);
                index += 4;
                bytes2.CopyTo(bytes, index);
                index += 4;
                bytes3.CopyTo(bytes, index);
                index += 4;
                bytes4.CopyTo(bytes, index);
                index += 4;
                bytes5.CopyTo(bytes, index);
                index += 4;
                bytes6.CopyTo(bytes, index);
    
                /// PropertyTagGpsLongitude    
                SetProperty(bitmap, 0x0004, bytes, 5);
            public void SetProperty(Bitmap image, Int32 propertyItemId, byte[] bytes, short propertyItemType)
            {
                System.Drawing.Imaging.PropertyItem propertyItem = (System.Drawing.Imaging.PropertyItem)(System.Activator.CreateInstance(typeof(System.Drawing.Imaging.PropertyItem), true)); 
                propertyItem.Id = propertyItemId;
                propertyItem.Value = bytes;
                propertyItem.Type = propertyItemType;
                propertyItem.Len = bytes.Length;
                image.SetPropertyItem(propertyItem);
            }
    
    
  • 相关阅读:
    2018 eclipse安装反编译插件
    Buffer flip()方法
    区块链2
    Mist 转移默认区块存储位置方法
    区块链1
    如何在Ubuntu下安装”.deb“、”.bin“、”.tar.gz“、”.tar.bz2“格式的软件包!
    eclipse 性能调优之内存分配
    linux中搭建java开发环境
    在 Ubuntu 14.04 上安装 Ubuntu Tweak 0.8.8
    Ubuntu各个版本的介绍
  • 原文地址:https://www.cnblogs.com/firesword/p/6093110.html
Copyright © 2011-2022 走看看