脱敏小软件

通过修改图像文件的Exif信息中经纬度信息,使图像数据脱敏

后续更新具体设计和思路

 项目地址:https://gitee.com/SmallUniv/ExifTool

/*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    /// <summary>
 2     /// 删除图像的经纬度信息
 3     /// </summary>
 4     public class ExifUtil
 5     {
 6         /// <summary>
 7         /// 删除图像的经纬度信息,覆盖原图像
 8         /// </summary>
 9         /// <param name="IN_File">文件路径</param>
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         /// <summary>
24         /// 删除图像的经纬度信息,并另存为
25         /// </summary>
26         /// <param name="IN_File">文件路径</param>
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         /// <summary>
39         /// 删除图像的经纬度信息
40         /// </summary>
41         /// <param name="image"></param>
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     }

 

posted @ 2018-12-12 09:56  JeffreyGoogle  阅读(1606)  评论(2编辑  收藏  举报