/// <summary> /// Takes manufacturer as input and returns photos made on particular camera /// </summary> /// <param name="manufacturer">Camera manufacturer name</param> public void FilterByCameraManufacturer(string manufacturer) { // Map directory in source folder string sourceDirectoryPath = Common.MapSourceFilePath(this.PhotosDirectory); // get jpeg files string[] files = Directory.GetFiles(sourceDirectoryPath, "*.jpg"); List <string> result = new List <string>(); foreach (string path in files) { // recognize file FormatBase format = FormatFactory.RecognizeFormat(path); // casting to JpegFormat if (format is JpegFormat) { JpegFormat jpeg = (JpegFormat)format; // get exif data JpegExifInfo exif = (JpegExifInfo)jpeg.GetExifInfo(); if (exif != null) { if (string.Compare(exif.Make, manufacturer, StringComparison.OrdinalIgnoreCase) == 0) { // add file path to list result.Add(Path.GetFileName(path)); } } } } Console.WriteLine(string.Join("\n", result)); }
/// <summary> /// Gets Exif info from Jpeg file /// </summary> public static void GetExifInfo() { try { //ExStart:GetExifPropertiesJpegImage // initialize JpegFormat JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath)); // get EXIF data JpegExifInfo exif = (JpegExifInfo)jpegFormat.GetExifInfo(); if (exif != null) { // get artist Console.WriteLine("Artist: {0}", exif.Artist); // get description Console.WriteLine("Description: {0}", exif.ImageDescription); // get user's comment Console.WriteLine("User Comment: {0}", exif.UserComment); // get user's Model Console.WriteLine("Model: {0}", exif.Model); // get user's Make Console.WriteLine("Make: {0}", exif.Make); // get user's CameraOwnerName Console.WriteLine("CameraOwnerName: {0}", exif.CameraOwnerName); } //ExEnd:GetExifPropertiesJpegImage } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates Exif info of Jpeg file and creates output file /// </summary> public static void UpdateExifInfo() { try { //ExStart:UpdateExifPropertiesJpegImage // initialize JpegFormat JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath)); // get EXIF data JpegExifInfo exif = (JpegExifInfo)jpegFormat.GetExifInfo(); if (exif == null) { // initialize EXIF data if null exif = new JpegExifInfo(); } // set artist exif.Artist = "Usman"; // set make exif.Make = "ABC"; // set model exif.Model = "S120"; // set the name of the camera's owner exif.CameraOwnerName = "Owner"; // set description exif.ImageDescription = "sample description"; // update EXIF data jpegFormat.SetExifInfo(exif); // commit changes jpegFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateExifPropertiesJpegImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates Exif info of Jpeg file and creates output file /// </summary> public static void UpdateExifInfo() { try { //ExStart:UpdateExifPropertiesJpegImage // initialize JpegFormat JpegFormat jpegFormat = new JpegFormat(Common.MapSourceFilePath(filePath)); // get EXIF data JpegExifInfo exif = (JpegExifInfo)jpegFormat.GetExifInfo(); if (exif == null) { // initialize EXIF data if null exif = new JpegExifInfo(); } // set artist exif.Artist = "Usman"; // set make exif.Make = "ABC"; // set model exif.Model = "S120"; // set the name of the camera's owner exif.CameraOwnerName = "Owner"; // set description exif.ImageDescription = "sample description"; // update EXIF data jpegFormat.SetExifInfo(exif); // commit changes jpegFormat.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateExifPropertiesJpegImage Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }