Beispiel #1
0
        /// <summary>
        /// Remvoes EXIF properties from an image.
        /// </summary>
        /// <param name="inputPath">file path of original image</param>
        /// <param name="outputPath">file path of modified image</param>
        /// <param name="exifTags">tags to remove</param>
        public static void RemoveExifData(string inputPath, string outputPath, IEnumerable <ExifTag> exifTags)
        {
            // minimally load image
            Image image;

            using (ExifReader.LoadImage(inputPath, out image))
            {
                using (image)
                {
                    ExifWriter.RemoveExifData(image, exifTags);
                    image.Save(outputPath);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds an EXIF property to an image.
        /// </summary>
        /// <param name="inputPath">file path of original image</param>
        /// <param name="outputPath">file path of modified image</param>
        /// <param name="property"></param>
        public static void AddExifData(string inputPath, string outputPath, ExifProperty property)
        {
            // minimally load image
            Image image;

            using (ExifReader.LoadImage(inputPath, out image))
            {
                using (image)
                {
                    ExifWriter.AddExifData(image, property);
                    image.Save(outputPath);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds a collection of EXIF properties to an image.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="properties"></param>
        public static void AddExifData(Image image, ExifPropertyCollection properties)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            if (properties == null || properties.Count < 1)
            {
                return;
            }

            foreach (ExifProperty property in properties)
            {
                ExifWriter.AddExifData(image, property);
            }
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="fullFile"></param>
        /// <returns></returns>
        /// <remarks>
        /// References:
        /// http://www.ee.cooper.edu/courses/course_pages/past_courses/EE458/TIFF/
        /// http://search.cpan.org/src/EXIFTOOL/Image-ExifTool-6.36/html/TagNames/Canon.html
        /// http://www.burren.cx/david/canon.html
        /// http://cpan.uwinnipeg.ca/htdocs/Image-ExifTool/Image/ExifTool/Canon.pm.html
        /// </remarks>
        public static PropertyItem[] DecodeIFD(byte[] bytes, FileStream fullFile)
        {
            int index = 0;
            int count = (int)BitConverter.ToUInt16(bytes, index);

            index += UInt16_Size;
            PropertyItem[] items = new PropertyItem[count];

            for (int i = 0; i < count; i++)
            {
                items[i] = ExifWriter.CreatePropertyItem();

                // read in the ID (2 bytes)
                items[i].Id = (int)BitConverter.ToUInt16(bytes, index);
                index      += UInt16_Size;

                // read in the Type (2 bytes)
                items[i].Type = (short)BitConverter.ToUInt16(bytes, index);
                index        += UInt16_Size;

                // read in the Length (4 bytes)
                items[i].Len = (int)BitConverter.ToUInt32(bytes, index);
                index       += UInt32_Size;

                int length = GetSizeOf(items[i].Type) * items[i].Len;
                if (length > 4)
                {
                    // read in the Data as offset (4 bytes)
                    int offset = (int)BitConverter.ToUInt32(bytes, index);
                    items[i].Value    = new byte[length];                 //CopyBytes(bytes, offset, length);
                    fullFile.Position = offset;
                    fullFile.Read(items[i].Value, 0, length);
                }
                else
                {
                    // read in the Data as byte[]
                    items[i].Value = CopyBytes(bytes, index, length);
                }
                index += UInt32_Size;
            }

            return(items);
        }
Beispiel #5
0
        /// <summary>
        /// Adds an EXIF property to an image.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="property"></param>
        public static void AddExifData(Image image, ExifProperty property)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (property == null)
            {
                return;
            }

            PropertyItem propertyItem;

            // The .NET interface for GDI+ does not allow instantiation of the
            // PropertyItem class. Therefore one must be stolen off the Image
            // and repurposed.  GDI+ uses PropertyItem by value so there is no
            // side effect when changing the values and reassigning to the image.
            if (image.PropertyItems == null || image.PropertyItems.Length < 1)
            {
                propertyItem = ExifWriter.CreatePropertyItem();
            }
            else
            {
                propertyItem = image.PropertyItems[0];
            }

            propertyItem.Id   = (int)property.Tag;
            propertyItem.Type = (short)property.Type;

            Type dataType = ExifDataTypeAttribute.GetDataType(property.Tag);

            propertyItem.Value = ExifEncoder.ConvertData(dataType, property.Type, property.Value);
            propertyItem.Len   = propertyItem.Value.Length;

            // This appears to not be necessary
            ExifWriter.RemoveExifData(image, property.Tag);
            image.SetPropertyItem(propertyItem);
        }
Beispiel #6
0
 /// <summary>
 /// Copies EXIF data from one image to another
 /// </summary>
 /// <param name="source"></param>
 /// <param name="dest"></param>
 public static void CloneExifData(Image source, Image dest)
 {
     ExifWriter.CloneExifData(source, dest, -1);
 }
Beispiel #7
0
 /// <summary>
 /// Remvoes EXIF properties from an image.
 /// </summary>
 /// <param name="image"></param>
 /// <param name="exifTags">tags to remove</param>
 public static void RemoveExifData(Image image, params ExifTag[] exifTags)
 {
     ExifWriter.RemoveExifData(image, (IEnumerable <ExifTag>)exifTags);
 }
Beispiel #8
0
 /// <summary>
 /// Remvoes EXIF properties from an image.
 /// </summary>
 /// <param name="inputPath">file path of original image</param>
 /// <param name="outputPath">file path of modified image</param>
 /// <param name="exifTags">tags to remove</param>
 public static void RemoveExifData(string inputPath, string outputPath, params ExifTag[] exifTags)
 {
     ExifWriter.RemoveExifData(inputPath, outputPath, (IEnumerable <ExifTag>)exifTags);
 }