//ExEnd:SourceJP2FilePath #region working with XMP data /// <summary> ///Gets XMP properties from JP2 file /// </summary> public static void GetXMPProperties() { try { //ExStart:GetXmpPropertiesJP2Image // initialize JP2Format Jp2Format jp2Format = new Jp2Format(Common.MapSourceFilePath(filePath)); // get XMP data XmpProperties xmpProperties = jp2Format.GetXmpProperties(); // show XMP data foreach (string key in xmpProperties.Keys) { try { XmpNodeView xmpNodeView = xmpProperties[key]; Console.WriteLine("[{0}] = {1}", xmpNodeView.Name, xmpNodeView.Value); } catch { } } //ExEnd:GetXmpPropertiesJP2Image } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Removes XMP data of Jpeg2000 file and creates output file /// </summary> public static void RemoveXMPData() { try { //ExStart:RemoveXmpPropertiesJp2Image // initialize JP2Format Jp2Format jp2Format = new Jp2Format(Common.MapSourceFilePath(filePath)); // remove XMP package jp2Format.RemoveXmpData(); // commit changes jp2Format.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:RemoveXmpPropertiesJp2Image Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates XMP data of JP2 file and creates output file /// </summary> public static void UpdateXMPProperties() { try { //ExStart:UpdateXmpPropertiesJpegImage // initialize JP2Format Jp2Format jp2Format = new Jp2Format(Common.MapSourceFilePath(filePath)); // get xmp wrapper XmpPacketWrapper xmpPacket = jp2Format.GetXmpData(); // create xmp wrapper if not exists if (xmpPacket == null) { xmpPacket = new XmpPacketWrapper(); } // check if DublinCore schema exists if (!xmpPacket.ContainsPackage(Namespaces.DublinCore)) { // if not - add DublinCore schema xmpPacket.AddPackage(new DublinCorePackage()); } // get DublinCore package DublinCorePackage dublinCorePackage = (DublinCorePackage)xmpPacket.GetPackage(Namespaces.DublinCore); string authorName = "New author"; string description = "New description"; string subject = "New subject"; string publisher = "New publisher"; string title = "New title"; // set author dublinCorePackage.SetAuthor(authorName); // set description dublinCorePackage.SetDescription(description); // set subject dublinCorePackage.SetSubject(subject); // set publisher dublinCorePackage.SetPublisher(publisher); // set title dublinCorePackage.SetTitle(title); // update XMP package jp2Format.SetXmpData(xmpPacket); // commit changes jp2Format.Save(Common.MapDestinationFilePath(filePath)); //ExEnd:UpdateXmpPropertiesJP2Image Console.WriteLine("File saved in destination folder."); } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Read Metadata of JP2 Format /// </summary> public static void ReadMetadataJP2() { try { //ExStart:ReadMetadataJP2 // initialize Jpeg2000 format Jp2Format jp2Format = new Jp2Format((Common.MapSourceFilePath(filePath))); // get height int width = jp2Format.Width; // get height int height = jp2Format.Height; // get comments string[] comments = jp2Format.Comments; foreach (var comm in comments) { Console.WriteLine("Comments: {0}", comm); } //ExEnd:ReadMetadataJP2 } catch (Exception exp) { Console.WriteLine(exp.Message); } }