博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#修改JPG图片EXIF信息中的GPS信息
阅读量:4302 次
发布时间:2019-05-27

本文共 2804 字,大约阅读时间需要 9 分钟。

///         /// 设置图片的经纬高        ///         /// 文件路径        /// 纬度        /// 经度        /// 高程        /// 保存路径        private void PRV_Operate(string IN_File,double IN_Lat,double IN_Lng,double IN_Alt,string IN_Save)        {            Image image = Image.FromFile(IN_File);            //构建版本            byte[] _version = { 2, 2, 0, 0 };            PRV_SetProperty(image, _version, 0x0000, 1);            //设置南北半球            PRV_SetProperty(image, BitConverter.GetBytes('N'), 0x0001, 2);            //设置纬度            PRV_SetProperty(image, PRV_GetLatlngByte(IN_Lat), 0x0002,5);            //设置东西半球            PRV_SetProperty(image, BitConverter.GetBytes('E'), 0x0003,2);            //设置经度            PRV_SetProperty(image, PRV_GetLatlngByte(IN_Lng), 0x0004, 5);            //设置高度在海平面上还是下            byte[] _altref = { 0 };//海平面上            PRV_SetProperty(image, _altref, 0x0005, 1);            //设置高度            byte[] _alt = new byte[8];            //类型为5可以通过分子/分母的形式表示小数,先乘后除            int v1 = (int)(IN_Alt * 10000);            int v2 = 10000;            Array.Copy(BitConverter.GetBytes(v1), 0, _alt, 0, 4);            Array.Copy(BitConverter.GetBytes(v2), 0, _alt, 4, 4);            PRV_SetProperty(image, _alt, 0x0006, 5);            image.Save(IN_Save);            image.Dispose();        }

用到的工具函数

///         /// 设置图片参数        ///         /// 图片        /// byte[] 要写入的内容        /// 字段ID        /// 值类型        private void PRV_SetProperty(Image IN_Image, byte[] IN_Content, int IN_Id,short IN_Type)        {            PropertyItem pi = IN_Image.PropertyItems[0];            pi.Id = IN_Id;            pi.Type = IN_Type;            pi.Value = IN_Content;            pi.Len = pi.Value.Length;            IN_Image.SetPropertyItem(pi);        }        ///         /// 经纬度转byte[]        ///         /// 待处理的经度或纬度        /// 
private byte[] PRV_GetLatlngByte(double IN_Latlng) { double temp; temp = Math.Abs(IN_Latlng); int degrees = (int)Math.Truncate(temp); temp = (temp - degrees) * 60; int minutes = (int)Math.Truncate(temp); temp = (temp - minutes) * 60; //分母设大提高精度 int secondsNominator = (int)Math.Truncate(10000000 * temp); int secondsDenoninator = 10000000; byte[] result = new byte[24]; Array.Copy(BitConverter.GetBytes(degrees), 0, result, 0, 4); Array.Copy(BitConverter.GetBytes(1), 0, result, 4, 4); Array.Copy(BitConverter.GetBytes(minutes), 0, result, 8, 4); Array.Copy(BitConverter.GetBytes(1), 0, result, 12, 4); Array.Copy(BitConverter.GetBytes(secondsNominator), 0, result, 16, 4); Array.Copy(BitConverter.GetBytes(secondsDenoninator), 0, result, 20, 4); return result; }

转载地址:http://wgqws.baihongyu.com/

你可能感兴趣的文章
RecyclerView 源码深入解析——绘制流程、缓存机制、动画等
查看>>
Android 面试题整理总结(一)Java 基础
查看>>
Android 面试题整理总结(二)Java 集合
查看>>
学习笔记_vnpy实战培训day02
查看>>
学习笔记_vnpy实战培训day03
查看>>
VNPY- VnTrader基本使用
查看>>
VNPY - CTA策略模块策略开发
查看>>
VNPY - 事件引擎
查看>>
MongoDB基本语法和操作入门
查看>>
学习笔记_vnpy实战培训day04_作业
查看>>
OCO订单(委托)
查看>>
学习笔记_vnpy实战培训day05
查看>>
学习笔记_vnpy实战培训day06
查看>>
Python super钻石继承
查看>>
回测引擎代码分析流程图
查看>>
Excel 如何制作时间轴
查看>>
股票网格交易策略
查看>>
matplotlib绘图跳过时间段的处理方案
查看>>
vnpy学习_04回测评价指标的缺陷
查看>>
ubuntu终端一次多条命令方法和区别
查看>>