通过修改图像文件的Exif信息中经纬度信息,使图像数据脱敏
后续更新具体设计和思路
项目地址:
/*PropertyItem 中对应属性 参考资料:https://docs.microsoft.com/en-us/dotnet/api/system.drawing.imaging.propertyitem.id?redirectedfrom=MSDN&view=netframework-4.7.2#System_Drawing_Imaging_PropertyItem_Id * ID Property tag 0x0000 PropertyTagGpsVer 0x0001 PropertyTagGpsLatitudeRef 0x0002 PropertyTagGpsLatitude 0x0003 PropertyTagGpsLongitudeRef 0x0004 PropertyTagGpsLongitude 0x0005 PropertyTagGpsAltitudeRef 0x0006 PropertyTagGpsAltitude */
1 ///2 /// 删除图像的经纬度信息 3 /// 4 public class ExifUtil 5 { 6 ///7 /// 删除图像的经纬度信息,覆盖原图像 8 /// 9 /// 文件路径10 public void DeleteCoord(string IN_File)11 {12 using (Stream ms = new MemoryStream(File.ReadAllBytes(IN_File)))13 {14 using (Image image = Image.FromStream(ms))15 {16 DeleteCoordInfo(image);17 image.Save(IN_File);18 }19 }20 }21 22 23 ///24 /// 删除图像的经纬度信息,并另存为25 /// 26 /// 文件路径27 public void DeleteCoord(string IN_File, string IN_Save)28 {29 using (Stream ms = new MemoryStream(File.ReadAllBytes(IN_File)))30 {31 using (Image image = Image.FromStream(ms))32 {33 DeleteCoordInfo(image);34 image.Save(IN_Save);35 }36 }37 }38 ///39 /// 删除图像的经纬度信息40 /// 41 /// 42 public static void DeleteCoordInfo(Image image)43 {44 int[] ids = new[] { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006 };45 foreach (int id in ids)46 {47 if (image.PropertyIdList.Contains(id))48 {49 image.RemovePropertyItem(id);50 }51 }52 }53 }