画像ファイルからEXIFヘッダーを削除する
Webに写真を載せる時なんかに気にする人が居るようだ。特定のヘッダーを残すとか考えずに、とりあえず全部消すのは割りと簡単。この方法だとEXIFヘッダー以外のメタ情報(IPTCとか)も消える。
using System; using System.IO; using System.Drawing; using System.Drawing.Imaging; namespace ExifAnonymizer { class ExifAnonymizer : IDisposable { private readonly string filePath = null; private readonly Bitmap image = null; public ExifAnonymizer(string filePath) { if (!File.Exists(filePath)) throw new FileNotFoundException(); this.filePath = filePath; using (var stream = new FileStream(filePath, FileMode.Open)) { image = new Bitmap(Bitmap.FromStream(stream)); } } public void Save() { Save(this.filePath); } public void Save(string filePath) { image.Save(filePath, ImageFormat.Jpeg); } public void Dispose() { if (image != null) image.Dispose(); } } class Program { static void Main(string[] args) { Array.ForEach(args, f => new ExifAnonymizer(f).Save()); } } }