.NET ez 2012-06-20
本篇利用 PropertyItem 讀取 圖片 內的 EXIF 資訊,此功能為 .Net 內建方式,不須匯入任何套件。 讀取 EXIF 資訊範例:
Image image = Image.FromFile("圖片路徑"); foreach (PropertyItem p in image.PropertyItems) { Console.WriteLine(p.Id); Console.WriteLine(p.Type); Console.WriteLine(p.Len); Console.WriteLine(p.Value); } image.Dispose();
複製 EXIF 資訊 a 檔案到 b 檔案:
Image image_F = Image.FromFile("a.jpg"); Image image_T = Image.FromFile("b.jpg"); foreach (PropertyItem p in image_F.PropertyItems) { image_T.SetPropertyItem(p); } image_T.Save("b.jpg"); image_T.Dispose(); image_F.Dispose();
變更 EXIF 資訊:
Image image = Image.FromFile("圖片路徑"); foreach (PropertyItem p in image.PropertyItems) { PropertyItem pi = image.PropertyItems[0]; pi.Id = 37510; //UserComment pi.Type = 2; pi.Value = System.Text.Encoding.UTF7.GetBytes("CSCWORM"); pi.Len = pi.Value.Length + 2; image.SetPropertyItem(pi); } image.Save("儲存路徑"); image.Dispose();
標籤: .NET
本文章網址:
https://www.ez2o.com/Blog/Post/csharp-Read-Image-EXIF-PropertyItem
https://www.ez2o.com/Blog/Post/211
https://www.ez2o.com/Blog/Post/csharp-Read-Image-EXIF-PropertyItem
https://www.ez2o.com/Blog/Post/211