Created
October 19, 2017 11:36
-
-
Save GroupDocsGists/8ab4ded217d192d563f285c3fba7c1c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For complete examples and data files, please go to https://github.com/groupdocsmetadata/GroupDocs_Metadata_NET | |
public class JpegPhotoParser | |
{ | |
// absolute path to the GroupDocs.Metadata license file. | |
private const string LicensePath = @"GroupDocs.Metadata.lic"; | |
// absolute path to the photos directory. | |
public string PhotosDirectory { get; set; } | |
static JpegPhotoParser() | |
{ | |
/* set product license | |
* uncomment following function if you have product license | |
* */ | |
//SetInternalLicense(); | |
} | |
public JpegPhotoParser(string photosDirectory) | |
{ | |
// check if directory exists | |
if (!Directory.Exists(Common.MapSourceFilePath( photosDirectory))) | |
{ | |
throw new DirectoryNotFoundException("Directory not found: " + photosDirectory); | |
} | |
// set property | |
this.PhotosDirectory = photosDirectory; | |
} | |
/// <summary> | |
/// Applies the product license | |
/// </summary> | |
private static void SetInternalLicense() | |
{ | |
License license = new License(); | |
license.SetLicense(LicensePath); | |
} | |
/// <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)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment