Пример #1
0
        /// <summary>
        /// Parses the EXIF data into a collection of properties.
        /// </summary>
        /// <param name="exifBytes">The EXIF bytes.</param>
        /// <returns>
        /// A collection containing the EXIF properties.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="exifBytes"/> is null.</exception>
        internal static ExifValueCollection Parse(byte[] exifBytes)
        {
            if (exifBytes == null)
            {
                throw new ArgumentNullException(nameof(exifBytes));
            }

            ExifValueCollection exifValues = null;

            MemoryStream stream = null;

            try
            {
                stream = new MemoryStream(exifBytes);

                Endianess?byteOrder = TryDetectTiffByteOrder(stream);

                if (byteOrder.HasValue)
                {
                    using (EndianBinaryReader reader = new(stream, byteOrder.Value))
                    {
                        stream = null;

                        ushort signature = reader.ReadUInt16();

                        if (signature == TiffConstants.Signature)
                        {
                            uint ifdOffset = reader.ReadUInt32();

                            List <ParserIFDEntry> entries = ParseDirectories(reader, ifdOffset);

                            exifValues = new ExifValueCollection(ConvertIFDEntriesToMetadataEntries(reader, entries));
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
            }
            finally
            {
                stream?.Dispose();
            }

            return(exifValues);
        }
Пример #2
0
 public ExifValueCollectionDebugView(ExifValueCollection collection)
 {
     this.collection = collection ?? throw new ArgumentNullException(nameof(collection));
 }