Reading data metadata from JPEG, XMP or EXIF in C#

前端 未结 5 1992
悲&欢浪女
悲&欢浪女 2020-12-14 18:56

I\'ve been looking around for a decent way of reading metadata (specifically, the date taken) from JPEG files in C#, and am coming up a little short. Existing information, a

5条回答
  •  失恋的感觉
    2020-12-14 19:34

    The following seems to work nicely, but if there's something bad about it, I'd appreciate any comments.

        public string GetDate(FileInfo f)
        {
            using(FileStream fs = new FileStream(f.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BitmapSource img = BitmapFrame.Create(fs);
                BitmapMetadata md = (BitmapMetadata)img.Metadata;
                string date = md.DateTaken;
                Console.WriteLine(date);
                return date;
            }
        }
    

提交回复
热议问题