示例#1
0
 private static void clearLocation(BitmapMetadata dest)
 {
     dest.RemoveQuery(LatitudeRefQuery);
     dest.RemoveQuery(LatitudeQuery);
     dest.RemoveQuery(LongitudeRefQuery);
     dest.RemoveQuery(LongitudeQuery);
 }
示例#2
0
        public static void MoveQuery(this BitmapMetadata bitmapMetadata, string sourceQuery, string destinationQuery, bool overWriteExistingData)
        {
            // Check Source Query exists
            if (bitmapMetadata.ContainsQuery(sourceQuery))
            {
                bool existingData = bitmapMetadata.ContainsQuery(destinationQuery);

                if (existingData && !overWriteExistingData)
                {
                    // Skip the copy and source the value
                    bitmapMetadata.RemoveQuery(sourceQuery);
                }
                else
                {
                    // Copy the Query
                    bitmapMetadata.CopyQuery(sourceQuery, destinationQuery);

                    // Finally remove old query
                    bitmapMetadata.RemoveQuery(sourceQuery);

                    // Ensure old query has been removed
                    if (!bitmapMetadata.ContainsQuery(destinationQuery))
                    {
                        throw new Exception("Move Query Failed");
                    }
                }
            }
        }
示例#3
0
        private void SetMetadata(BitmapMetadata bitmapMetadata)
        {
            if (Caption != null)
            {
                bitmapMetadata.Comment = Caption;
            }

            //the rest is gps stuff
            if (GPSLatitude.HasValue && GPSLongitude.HasValue)
            {
                bitmapMetadata.SetQuery(GPSLatitudeQuery, ConvertCoordinate(GPSLatitude.Value));
                bitmapMetadata.SetQuery(GPSLongitudeQuery, ConvertCoordinate(GPSLongitude.Value));

                byte[] gpsVersionNumbers = new byte[4];
                gpsVersionNumbers[0] = 0;
                gpsVersionNumbers[1] = 0;
                gpsVersionNumbers[2] = 2;
                gpsVersionNumbers[3] = 2;
                bitmapMetadata.SetQuery(GPSVersionIDQuery, gpsVersionNumbers);

                string northOrSouth = (GPSLatitude.Value >= 0) ? "N" : "S";
                bitmapMetadata.SetQuery(GPSLatitudeRefQuery, northOrSouth);

                string eastOrWest = (GPSLongitude.Value >= 0) ? "E" : "W";
                bitmapMetadata.SetQuery(GPSLongitudeRefQuery, eastOrWest);

                string gpsTime = GPSDateTime.Value.ToString("yyyy:MM:dd HH:mm:ss");
            }
            else
            {
                bitmapMetadata.RemoveQuery(GPSLatitudeQuery);
                bitmapMetadata.RemoveQuery(GPSLongitudeQuery);
                bitmapMetadata.RemoveQuery(GPSLatitudeRefQuery);
                bitmapMetadata.RemoveQuery(GPSLongitudeRefQuery);
            }

            if (GPSDateTime.HasValue)
            {
                bitmapMetadata.SetQuery(GPSTimeStampQuery, ConvertGpsTime(GPSDateTime.Value));
                bitmapMetadata.SetQuery(GPSDateStampQuery, ConvertGpsDate(GPSDateTime.Value));
            }
        }
示例#4
0
 public static void SetQueryOrRemove(this BitmapMetadata bitmapMetadata, string query, object value, bool whenTrueRemoveQuery)
 {
     if (whenTrueRemoveQuery)
     {
         bitmapMetadata.RemoveQuery(query);
     }
     else
     {
         bitmapMetadata.SetQuery(query, value);
     }
 }
示例#5
0
        public static void MoveStruct(this BitmapMetadata bitmapMetadata, string sourceNameSpace, string sourceStructName, string destinationNameSpace, string destinationStructName, bool overWriteExistingData, bool ignoreInvalidSource)
        {
            // Rewrite Structnames
            string sourceStruct = @"/xmp/" + sourceNameSpace + sourceStructName;
            string sourceQuery  = sourceStruct + "/" + sourceNameSpace;

            string destinationStruct = @"/xmp/" + destinationNameSpace + destinationStructName;
            string destinationQuery  = destinationStruct + "/" + destinationNameSpace;

            // Check Source exists
            bool sourceExists = bitmapMetadata.ContainsQuery(sourceStruct);

            if (sourceExists)
            {
                // Create a new Struct, if it doesn't exist
                if (!bitmapMetadata.ContainsQuery(destinationStruct))
                {
                    bitmapMetadata.SetQuery(destinationStruct, new BitmapMetadata("xmpstruct"));
                }

                List <string> sourceSubQueries = bitmapMetadata.GetSubQueries(sourceStruct);

                // Loop through all data in the struct
                foreach (string sourceProperty in sourceSubQueries)
                {
                    // Construct the full query
                    string destinationProperty = sourceProperty.Replace(sourceQuery, destinationQuery);

                    bitmapMetadata.MoveQuery(sourceProperty, destinationProperty, overWriteExistingData);
                }

                // Remove the old struct
                bitmapMetadata.RemoveQuery(sourceStruct);

                // Get Destination Queries
                List <string> destinationSubQueries = bitmapMetadata.GetSubQueries(destinationStruct);

                // Check the destination has at least as many subqueries as the source
                if (destinationSubQueries.Count < sourceSubQueries.Count)
                {
                    throw new Exception("Source Struct was not fully moved to Destination");
                }
            }
            else if (!sourceExists && !ignoreInvalidSource)
            {
                throw new Exception("Source Struct does not exist:" + sourceStruct);
            }
        }
示例#6
0
        public static void RemoveQuerySafe(this BitmapMetadata metadata, string query)
        {
            if (metadata == null || string.IsNullOrWhiteSpace(query))
            {
                return;
            }

            try
            {
                if (metadata.ContainsQuery(query))
                {
                    metadata.RemoveQuery(query);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception while trying to remove metadata entry at position: {query}");
                Debug.WriteLine(ex);
            }
        }
示例#7
0
        public static void RemoveQuerySafe(this BitmapMetadata metadata, string query)
        {
            if (metadata == null || string.IsNullOrWhiteSpace(query))
            {
                return;
            }

            try
            {
                if (metadata.ContainsQuery(query))
                {
                    metadata.RemoveQuery(query);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                Debug.WriteLine($"Exception while trying to remove metadata entry at position: {query}");
                Debug.WriteLine(ex);
            }
        }
示例#8
0
        public static void CopyQuery(this BitmapMetadata bitmapMetadata, string sourceQuery, string destinationQuery)
        {
            // Check Source Query exists
            if (bitmapMetadata.ContainsQuery(sourceQuery))
            {
                // Garb source object
                object sourceObject = bitmapMetadata.GetQuery(sourceQuery);

                // Remove destination Query
                bitmapMetadata.RemoveQuery(sourceQuery);

                // Set destination Query
                bitmapMetadata.SetQuery(destinationQuery, sourceObject.ToString());

                // Grab Destination Query
                object destinationObject = bitmapMetadata.GetQuery(destinationQuery);

                // Check Type and value.ToString() match
                if (sourceObject.GetType() != destinationObject.GetType() || sourceObject.ToString() != destinationObject.ToString())
                {
                    throw new Exception("Copy Query Failed");
                }
            }
        }
示例#9
0
        public static async Task <Photo.Metadata> SetMetadata(Photo photo, BitmapMetadata dest)
        {
            var source = GetMetadata(dest);
            await photo.Dispatcher.InvokeAsync(() => {
                source.Title       = photo.Title;
                source.Author      = photo.Photographer;
                source.DateTaken   = photo.DateTaken;
                source.Location    = photo.Location;
                source.Orientation = 1;
            });

            if (!string.IsNullOrWhiteSpace(source.Title))
            {
                var title = toUniversalNewline(source.Title.Trim());
                var bytes = Encoding.UTF8.GetBytes(title);
                dest.SetQuery(TitleQuery, Encoding.Default.GetString(bytes));
                var utf16bytes = Encoding.Unicode.GetBytes(title + '\0');
                dest.SetQuery(WinTitleQuery, utf16bytes);
                dest.Title = title;
            }
            else
            {
                dest.Title = string.Empty;
                foreach (var query in TitleRemoveQueries)
                {
                    dest.RemoveQuery(query);
                }
            }
            if (!string.IsNullOrWhiteSpace(source.Author))
            {
                var bytes = Encoding.UTF8.GetBytes(source.Author);
                dest.Author = new ReadOnlyCollection <string>(new string[] {
                    Encoding.Default.GetString(bytes)
                });
            }
            else
            {
                dest.Author = EmptyStringCollection;
                foreach (var query in AuthorRemoveQueries)
                {
                    dest.RemoveQuery(query);
                }
            }
            if (source.DateTaken.HasValue)
            {
                var bytes = Encoding.ASCII.GetBytes(
                    source.DateTaken.Value.ToString(ExifDateFormat, CultureInfo.InvariantCulture));
                dest.SetQuery(DateTakenQuery, Encoding.Default.GetString(bytes));
            }
            else
            {
                dest.RemoveQuery(DateTakenQuery);
                dest.RemoveQuery(DateTakenSubsecQuery);
            }
            if (source.Location != null)
            {
                setLocation(dest, source.Location);
            }
            else
            {
                clearLocation(dest);
            }
            return(source);
        }
示例#10
0
        public void Remove(int propId)
        {
            string query = Query(propId);

            fNewMetadata.RemoveQuery(query);
        }
        private void SetOrientationMetadata(BitmapMetadata bitmapMetadata, MetadataItemName metaName, MetaPersistAction persistAction)
        {
            switch (persistAction)
            {
                case MetaPersistAction.Delete:
                    bitmapMetadata.RemoveQuery(UpdatableMetaItems[metaName]);
                    break;

                case MetaPersistAction.Save:
                    IGalleryObjectMetadataItem orientationMeta;
                    if (GalleryObject.MetadataItems.TryGetMetadataItem(metaName, out orientationMeta))
                    {
                        ushort orientationRaw;
                        if (UInt16.TryParse(orientationMeta.RawValue, out orientationRaw) && MetadataEnumHelper.IsValidOrientation((Orientation)orientationRaw))
                        {
                            bitmapMetadata.SetQuery(UpdatableMetaItems[metaName], orientationRaw);
                        }
                    }
                    break;

                default:
                    throw new InvalidEnumArgumentException(String.Format(CultureInfo.CurrentCulture, "This function is not designed to handle the enumeration value {0}. The function must be updated.", persistAction));
            }
        }