private void WriteXmpMetaData(string imageFilePath, MasterImage masterImage, bool alwaysWriteMetadata, bool preview) { bool writeMetadata = false; IXmpMeta xmp = XmpMetaFactory.Create(); if ((!String.IsNullOrEmpty(masterImage.Caption) && !IsEquivalent(masterImage.Caption, imageFilePath)) || alwaysWriteMetadata) { xmp.AppendArrayItem(XmpConstants.NsDC, "dc:title", new PropertyOptions { IsArrayAlternate = true }, masterImage.Caption, null); writeMetadata = true; } if (!String.IsNullOrEmpty(masterImage.Comment)) { xmp.AppendArrayItem(XmpConstants.NsDC, "dc:description", new PropertyOptions { IsArrayAlternate = true }, masterImage.Comment, null); writeMetadata = true; } if (masterImage.Rating != null && (int)masterImage.Rating > 0) { xmp.SetProperty(XmpConstants.NsXmp, "xmp:Rating", ((int)masterImage.Rating).ToString()); writeMetadata = true; } // TODO: Handle faces. if (writeMetadata) { string metaFilePath = Path.ChangeExtension(imageFilePath, ".xmp"); if (File.Exists(metaFilePath)) { Console.Error.WriteLine("ERROR: XMP meta file already exists, skipping '" + metaFilePath + "'."); } else if (!preview) { Directory.CreateDirectory(Path.GetDirectoryName(metaFilePath)); using (var stream = File.OpenWrite(metaFilePath)) { XmpMetaFactory.Serialize(xmp, stream, new SerializeOptions { OmitPacketWrapper = true }); } numMetadataFilesCreated++; } } }
/** * Flushes and closes the XmpWriter. * @throws IOException */ virtual public void Close() { if (outputStream == null) { return; } try { XmpMetaFactory.Serialize(xmpMeta, outputStream, serializeOptions); outputStream = null; } catch (XmpException xmpExc) { throw new IOException(xmpExc.Message); } }
/** * Flushes and closes the XmpWriter. * @throws IOException */ virtual public void Serialize(Stream externalOutputStream) { XmpMetaFactory.Serialize(xmpMeta, externalOutputStream, serializeOptions); }