コード例 #1
0
ファイル: Program.cs プロジェクト: JayesonLS/iPhotoExtractor
        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++;
                }
            }
        }
コード例 #2
0
        /** Sets the identifier.
         *
         * @param xmpMeta
         * @param id
         */

        public static void SetIdentifiers(IXmpMeta xmpMeta, String[] id) {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, IDENTIFIER, true, true);
            for (int i = 0; i < id.Length; i++) {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, IDENTIFIER, new PropertyOptions(PropertyOptions.ARRAY), id[i],
                                        null);
            }
        }
コード例 #3
0
        /** Sets the identifier.
         *
         * @param xmpMeta
         * @param id
         */

        public static void SetIdentifiers(IXmpMeta xmpMeta, String[] id)
        {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, IDENTIFIER, true, true);
            for (int i = 0; i < id.Length; i++)
            {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, IDENTIFIER, new PropertyOptions(PropertyOptions.ARRAY), id[i],
                                        null);
            }
        }
コード例 #4
0
        /**
         * Sets a subject.
         *
         * @param xmpMeta
         * @param subject array of subjects
         */

        public static void SetSubject(IXmpMeta xmpMeta, String[] subject)
        {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, SUBJECT, true, true);
            for (int i = 0; i < subject.Length; i++)
            {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, SUBJECT, new PropertyOptions(PropertyOptions.ARRAY), subject[i],
                                        null);
            }
        }
コード例 #5
0
        /**
         * Sets an array of publishers.
         *
         * @param xmpMeta
         * @param publisher
         */

        public static void SetPublisher(IXmpMeta xmpMeta, String[] publisher)
        {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, PUBLISHER, true, true);
            for (int i = 0; i < publisher.Length; i++)
            {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, PUBLISHER, new PropertyOptions(PropertyOptions.ARRAY_ORDERED),
                                        publisher[i], null);
            }
        }
コード例 #6
0
        /**
         * Sets an array of authors.
         *
         * @param xmpMeta
         * @param author
         */

        public static void SetAuthor(IXmpMeta xmpMeta, String[] author)
        {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, CREATOR, true, true);
            for (int i = 0; i < author.Length; i++)
            {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, CREATOR, new PropertyOptions(PropertyOptions.ARRAY_ORDERED),
                                        author[i], null);
            }
        }
コード例 #7
0
        /**
         * Adds a description.
         *
         * @param xmpMeta
         * @param desc
         */

        public static void AddDescription(IXmpMeta xmpMeta, String desc)
        {
            xmpMeta.AppendArrayItem(XmpConst.NS_DC, DESCRIPTION, new PropertyOptions(PropertyOptions.ARRAY_ALTERNATE),
                                    desc, null);
        }
コード例 #8
0
        /**
         * Adds a title.
         *
         * @param xmpMeta
         * @param title
         */

        public static void AddTitle(IXmpMeta xmpMeta, String title)
        {
            xmpMeta.AppendArrayItem(XmpConst.NS_DC, TITLE, new PropertyOptions(PropertyOptions.ARRAY_ALTERNATE), title,
                                    null);
        }
コード例 #9
0
        /**
         * Adds a single publisher.
         *
         * @param xmpMeta
         * @param publisher
         */

        public static void AddPublisher(IXmpMeta xmpMeta, String publisher)
        {
            xmpMeta.AppendArrayItem(XmpConst.NS_DC, PUBLISHER, new PropertyOptions(PropertyOptions.ARRAY_ORDERED),
                                    publisher, null);
        }
コード例 #10
0
        /**
         * Adds a single author.
         *
         * @param xmpMeta
         * @param author
         */

        public static void AddAuthor(IXmpMeta xmpMeta, String author)
        {
            xmpMeta.AppendArrayItem(XmpConst.NS_DC, CREATOR, new PropertyOptions(PropertyOptions.ARRAY_ORDERED), author,
                                    null);
        }
コード例 #11
0
        /**
         * Adds a single author.
         *
         * @param xmpMeta
         * @param author
         */

        public static void AddAuthor(IXmpMeta xmpMeta, String author) {
            xmpMeta.AppendArrayItem(XmpConst.NS_DC, CREATOR, new PropertyOptions(PropertyOptions.ARRAY_ORDERED), author,
                                    null);
        }
コード例 #12
0
        /**
         * Adds a description.
         *
         * @param xmpMeta
         * @param desc
         */

        public static void AddDescription(IXmpMeta xmpMeta, String desc) {
            xmpMeta.AppendArrayItem(XmpConst.NS_DC, DESCRIPTION, new PropertyOptions(PropertyOptions.ARRAY_ALTERNATE),
                                    desc, null);

        }
コード例 #13
0
        /**
         * Adds a subject.
         *
         * @param xmpMeta
         * @param subject
         */

        public static void AddSubject(IXmpMeta xmpMeta, String subject) {
            xmpMeta.AppendArrayItem(XmpConst.NS_DC, SUBJECT, new PropertyOptions(PropertyOptions.ARRAY), subject, null);
        }
コード例 #14
0
        /**
         * Adds a title.
         *
         * @param xmpMeta
         * @param title
         */

        public static void AddTitle(IXmpMeta xmpMeta, String title) {
            xmpMeta.AppendArrayItem(XmpConst.NS_DC, TITLE, new PropertyOptions(PropertyOptions.ARRAY_ALTERNATE), title,
                                    null);
        }
コード例 #15
0
        /**
         * Sets an array of publishers.
         *
         * @param xmpMeta
         * @param publisher
         */

        public static void SetPublisher(IXmpMeta xmpMeta, String[] publisher) {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, PUBLISHER, true, true);
            for (int i = 0; i < publisher.Length; i++) {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, PUBLISHER, new PropertyOptions(PropertyOptions.ARRAY_ORDERED),
                                        publisher[i], null);
            }
        }
コード例 #16
0
        /**
         * Adds a single publisher.
         *
         * @param xmpMeta
         * @param publisher
         */

        public static void AddPublisher(IXmpMeta xmpMeta, String publisher) {
            xmpMeta.AppendArrayItem(XmpConst.NS_DC, PUBLISHER, new PropertyOptions(PropertyOptions.ARRAY_ORDERED),
                                    publisher, null);
        }
コード例 #17
0
        /**
         * Sets an array of authors.
         *
         * @param xmpMeta
         * @param author
         */

        public static void SetAuthor(IXmpMeta xmpMeta, String[] author) {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, CREATOR, true, true);
            for (int i = 0; i < author.Length; i++) {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, CREATOR, new PropertyOptions(PropertyOptions.ARRAY_ORDERED),
                                        author[i], null);
            }
        }
コード例 #18
0
        /**
         * Adds a subject.
         *
         * @param xmpMeta
         * @param subject
         */

        public static void AddSubject(IXmpMeta xmpMeta, String subject)
        {
            xmpMeta.AppendArrayItem(XmpConst.NS_DC, SUBJECT, new PropertyOptions(PropertyOptions.ARRAY), subject, null);
        }
コード例 #19
0
        /**
         * Simplifies the construction of an array by not requiring that you pre-create an empty array.
         * The array that is assigned is created automatically if it does not yet exist. Each call to
         * AppendArrayItem() appends an item to the array.
         *
         * @param schemaNS  The namespace URI for the array.
         * @param arrayName The name of the array. May be a general path expression, must not be null or
         *                  the empty string.
         * @param value     the value of the array item.
         * @throws XMPException Wraps all errors and exceptions that may occur.
         */

        virtual public void AppendArrayItem(String schemaNS, String arrayName, String value)
        {
            xmpMeta.AppendArrayItem(schemaNS, arrayName, new PropertyOptions(PropertyOptions.ARRAY), value, null);
        }
コード例 #20
0
        /**
         * Sets a subject.
         *
         * @param xmpMeta
         * @param subject array of subjects
         */

        public static void SetSubject(IXmpMeta xmpMeta, String[] subject) {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, SUBJECT, true, true);
            for (int i = 0; i < subject.Length; i++) {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, SUBJECT, new PropertyOptions(PropertyOptions.ARRAY), subject[i],
                                        null);
            }
        }