示例#1
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);
        }
示例#2
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);
        }