Пример #1
0
        protected override void write(XMPLib.MetaData xmpMetaDataWriter, BaseMetadata media)
        {
            ImageMetadata image = media as ImageMetadata;

            if (image.FlashFired != null)
            {
                xmpMetaDataWriter.setStructField(Consts.XMP_NS_EXIF, "Flash", "http://ns.adobe.com/exif/1.0/", "exif:Fired", image.FlashFired.Value.ToString(), 0);
            }
            else
            {
                xmpMetaDataWriter.deleteStructField(Consts.XMP_NS_EXIF, "Flash", "http://ns.adobe.com/exif/1.0/", "exif:Fired");
            }

            // integers

            if (image.LightSource != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "LightSource", image.LightSource.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "LightSource");
            }

            if (image.MeteringMode != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "MeteringMode", image.MeteringMode.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "MeteringMode");
            }

            if (image.Saturation != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "Saturation", image.Saturation.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "Saturation");
            }

            if (image.SceneCaptureType != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "SceneCaptureType", image.SceneCaptureType.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "SceneCaptureType");
            }

            if (image.SensingMethod != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "SensingMethod", image.SensingMethod.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "SensingMethod");
            }

            if (image.Sharpness != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "Sharpness", image.Sharpness.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "Sharpness");
            }

            if (image.Orientation != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "Orientation", image.Orientation.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "Orientation");
            }

            if (image.Contrast != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "Contrast", image.Contrast.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "Contrast");
            }

            if (image.SubjectDistanceRange != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "SubjectDistanceRange", image.SubjectDistanceRange.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "SubjectDistanceRange");
            }

            if (image.WhiteBalance != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "WhiteBalance", image.WhiteBalance.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "WhiteBalance");
            }

            if (image.ExposureProgram != null)
            {
                xmpMetaDataWriter.setProperty_Int(Consts.XMP_NS_EXIF, "ExposureProgram", image.ExposureProgram.Value);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "ExposureProgram");
            }

            // strings

            if (image.CameraMake != null)
            {
                xmpMetaDataWriter.setProperty(Consts.XMP_NS_TIFF, "Make", image.CameraMake, Consts.PropOptions.XMP_NoOptions);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_TIFF, "Make");
            }

            if (image.CameraModel != null)
            {
                xmpMetaDataWriter.setProperty(Consts.XMP_NS_TIFF, "Model", image.CameraModel, Consts.PropOptions.XMP_NoOptions);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_TIFF, "Model");
            }

            if (image.Lens != null)
            {
                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF_Aux, "Lens", image.Lens, Consts.PropOptions.XMP_NoOptions);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF_Aux, "Lens");
            }

            if (image.SerialNumber != null)
            {
                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF_Aux, "SerialNumber", image.SerialNumber, Consts.PropOptions.XMP_NoOptions);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF_Aux, "SerialNumber");
            }

            // fractions

            if (image.ExposureTime != null)
            {
                String result = approximateFraction(image.ExposureTime.Value);

                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "ExposureTime", result, 0);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "ExposureTime");
            }

            if (image.FNumber != null)
            {
                String result = approximateFraction(image.FNumber.Value);

                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "FNumber", result, 0);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "FNumber");
            }

            if (image.ExposureBiasValue != null)
            {
                String result = approximateFraction(image.ExposureBiasValue.Value);

                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "ExposureBiasValue", result, 0);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "ExposureBiasValue");
            }

            if (image.FocalLength != null)
            {
                String result = approximateFraction(image.FocalLength.Value);

                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "FocalLength", result, 0);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "FocalLength");
            }

            if (image.SubjectDistance != null)
            {
                String result = approximateFraction(image.SubjectDistance.Value);

                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "SubjectDistance", result, 0);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "SubjectDistance");
            }

            if (image.ShutterSpeedValue != null)
            {
                String result = approximateFraction(image.ShutterSpeedValue.Value);

                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "ShutterSpeedValue", result, 0);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "ShutterSpeedValue");
            }

            if (image.ISOSpeedRating != null)
            {
                if (xmpMetaDataWriter.doesArrayItemExist(Consts.XMP_NS_EXIF, "ISOSpeedRatings", 1))
                {
                    xmpMetaDataWriter.setArrayItem(Consts.XMP_NS_EXIF, "ISOSpeedRatings", 1, image.ISOSpeedRating.Value.ToString(), 0);
                }
                else
                {
                    xmpMetaDataWriter.appendArrayItem(Consts.XMP_NS_EXIF, "ISOSpeedRatings",
                                                      Consts.PropOptions.XMP_PropArrayIsOrdered, image.ISOSpeedRating.Value.ToString(), 0);
                }
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "ISOSpeedRatings");
            }

            base.write(xmpMetaDataWriter, media);
        }
Пример #2
0
        protected virtual void write(XMPLib.MetaData xmpMetaDataWriter, BaseMetadata media)
        {
            if (media.Title != null)
            {
                xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "title", "en", "en-US", media.Title);
            }

            if (media.Rating != null)
            {
                xmpMetaDataWriter.setProperty_Float(Consts.XMP_NS_XMP, "Rating", media.Rating.Value);
                //xmpMetaDataWriter.setProperty(Consts.XMP_NS_XMP, "Rating", media.Rating.ToString(), Consts.PropOptions.XMP_DeleteExisting);
            }

            if (media.Description != null)
            {
                xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "description", "en", "en-US", media.Description);
            }

            if (media.Software != null)
            {
                xmpMetaDataWriter.setProperty(Consts.XMP_NS_XMP, "CreatorTool", media.Software,
                                              Consts.PropOptions.XMP_DeleteExisting);
            }

            if (media.Author != null)
            {
                if (xmpMetaDataWriter.doesArrayItemExist(Consts.XMP_NS_DC, "creator", 1))
                {
                    xmpMetaDataWriter.setArrayItem(Consts.XMP_NS_DC, "creator", 1, media.Author, 0);
                }
                else
                {
                    xmpMetaDataWriter.appendArrayItem(Consts.XMP_NS_DC, "creator",
                                                      Consts.PropOptions.XMP_PropArrayIsOrdered, media.Author, 0);
                }
            }

            /*if (media.Thumbnail != null)
             * {
             *  string imageData = MediaViewer.Infrastructure.Utils.ImageUtils.imageToJpegBase64String(media.Thumbnail.Image);
             *
             *  xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "format", "JPEG", (uint)Consts.PropOptions.XMP_NoOptions);
             *  xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "width", media.Thumbnail.Image.Width.ToString(), (uint)Consts.PropOptions.XMP_NoOptions);
             *  xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "height", media.Thumbnail.Image.Height.ToString(), (uint)Consts.PropOptions.XMP_NoOptions);
             *  xmpMetaDataWriter.setStructField(Consts.XMP_NS_XMP, "xmpGImg", Consts.XMP_NS_XMP_Image, "image", imageData, (uint)Consts.PropOptions.XMP_NoOptions);
             * }*/

            if (media.Copyright != null)
            {
                xmpMetaDataWriter.setLocalizedText(Consts.XMP_NS_DC, "rights", "en", "en-US", media.Copyright);
            }

            if (media.CreationDate != null)
            {
                xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "CreateDate", media.CreationDate.Value);
            }

            if (media.MetadataDate == null)
            {
                xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "MetadataDate", DateTime.Now);
            }
            else
            {
                xmpMetaDataWriter.setProperty_Date(Consts.XMP_NS_XMP, "ModifyDate", DateTime.Now);
            }


            int nrTags = xmpMetaDataWriter.countArrayItems(Consts.XMP_NS_DC, "subject");

            for (int i = nrTags; i > 0; i--)
            {
                xmpMetaDataWriter.deleteArrayItem(Consts.XMP_NS_DC, "subject", i);
            }

            foreach (Tag tag in media.Tags)
            {
                xmpMetaDataWriter.appendArrayItem(Consts.XMP_NS_DC, "subject",
                                                  Consts.PropOptions.XMP_PropArrayIsUnordered, tag.Name, 0);
            }

            GeoTagCoordinatePair geoTag = new GeoTagCoordinatePair(media.Latitude, media.Longitude);

            if (!geoTag.IsEmpty)
            {
                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "GPSLatitude", geoTag.LatCoord, 0);
                xmpMetaDataWriter.setProperty(Consts.XMP_NS_EXIF, "GPSLongitude", geoTag.LonCoord, 0);
            }
            else
            {
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "GPSLatitude");
                xmpMetaDataWriter.deleteProperty(Consts.XMP_NS_EXIF, "GPSLongitude");
            }

            if (xmpMetaDataWriter.canPutXMP())
            {
                xmpMetaDataWriter.putXMP();
            }
            else
            {
                throw new Exception("Format does not support XMP metadata");
            }
        }