public static ICorrection Reader(ExifDictionary exif) { var correction = new CorrectionDto(); if (exif == null) { return correction; } var enumerator = exif.GetDictionaryEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current.ToString() == "ColorLabP") { // Advance the enumerator to the start of the relevant data. enumerator.MoveNext(); enumerator.MoveNext(); enumerator.MoveNext(); // Read the data into a new CorrectionDto correction.Saturation = ConvertSaturation(ReadFloat(enumerator)); correction.Contrast = ConvertContrast(ReadFloat(enumerator)); correction.Midpoint = ConvertMidpoint(ReadFloat(enumerator)); correction.Red = ConvertColor(ReadFloat(enumerator)); correction.Green = ConvertColor(ReadFloat(enumerator)); correction.Blue = ConvertColor(ReadFloat(enumerator)); correction.Rotate = ConvertRotation(ReadFloat(enumerator)); // Exit the loop. break; } } return correction; }
private static void ResizeAndPreserveMetadata() { using (var jpegReader = new JpegReader("../../../../_Input/Chicago.jpg")) using (var resizer = new Resize(jpegReader.Width / 2, 0)) using (var jpegWriter = new JpegWriter("../../../../_Output/ResizeAndPreserveMetadata.jpg")) { // Read EXIF var exif = jpegReader.Exif; // Check if loaded image contains EXIF metadata if (exif == null) { exif = new ExifDictionary(); } exif[ExifDictionary.Software] = "Aurigma Graphics Mill"; // Read IPTC var iptc = jpegReader.Iptc; // Check if loaded image contains IPTC metadata if (iptc == null) { iptc = new IptcDictionary(); } iptc[IptcDictionary.Keyword] = "mountain"; // Read Adobe resource blocks var adobeResources = jpegReader.AdobeResources; // Check if loaded image contains Adobe image resource blocks if (adobeResources == null) { adobeResources = new AdobeResourceDictionary(); } // Create new adobe image resource block containing copyright metadata var arBlock = new AdobeResourceBlock("Copyright", new byte[] { 1 }); // Set this block to the item with 0x040A ID (copyright flag) adobeResources[0x040A] = arBlock; // Read XMP var xmp = new XmpData(); //Check if loaded image contains XMP metadata if (jpegReader.Xmp != null) { xmp.Load(jpegReader.Xmp); } // Create a node containing dc:contributor metadata var node = new XmpValueNode(XmpNodeType.SimpleProperty, "John Doe", XmpTagNames.DCContributor); xmp.AddNode(node); // Write metadata jpegWriter.Exif = exif; jpegWriter.Iptc = iptc; jpegWriter.AdobeResources = adobeResources; jpegWriter.Xmp = xmp.Save(); Pipeline.Run(jpegReader + resizer + jpegWriter); } }
protected DpofImageFormat GetImageFormat(string filePath) { ExifDictionary exif = null; if (filePath.EndsWith("jpg", StringComparison.InvariantCultureIgnoreCase) || filePath.EndsWith("jpeg", StringComparison.InvariantCultureIgnoreCase)) { try { using (var jpegReader = new JpegReader(filePath)) { exif = jpegReader.Exif; if (exif != null) { try { var version = exif.GetItemString(ExifDictionary.ExifVersion); if (version == "0220") { return(DpofImageFormat.EXIF2J); } if (version == "0210") { return(DpofImageFormat.EXIF1J); } } catch (Exception) { } } return(DpofImageFormat.JFIF); } } catch (Exception) { exif = null; } } if (filePath.EndsWith("tiff", StringComparison.InvariantCultureIgnoreCase) || filePath.EndsWith("tif", StringComparison.InvariantCultureIgnoreCase)) { try { using (var tiffReader = new TiffReader(filePath)) { exif = tiffReader.Exif; if (exif != null) { try { var version = exif.GetItemString(ExifDictionary.ExifVersion); if (version == "0220") { return(DpofImageFormat.EXIF2T); } if (version == "0210") { return(DpofImageFormat.EXIF1T); } } catch (Exception) { } } return(DpofImageFormat.UNDEF); } } catch (Exception) { exif = null; } } if (exif != null) { } return(DpofImageFormat.UNDEF); }