Ejemplo n.º 1
0
        /// <summary>
        /// Returns the number of times the shutter has opened on the camera.
        /// </summary>
        /// <returns>The number of times the camera's shutter has opened.</returns>
        public int ShutterCount()
        {
            // See if we can pull the data from a makernote.

            string make = Make().ToLowerInvariant();

            if (make.Contains("nikon") == true && ExifIFD != null)
            {
                // Find the maker note...

                var maker_note_field = ExifIFD.GetTag(MakerNote);

                if (maker_note_field != null)
                {
                    byte[] maker_note_buffer = new byte[maker_note_field.Count - 10];

                    Array.Copy(TIFFData, maker_note_field.OffsetToValue + 10, maker_note_buffer, 0, maker_note_field.Count - 10);

                    var tiff_header = new TIFFHeader();

                    if (tiff_header.FromBytes(maker_note_buffer, 0) == true)
                    {
                        var maker_note = new ImageFileDirectory();

                        if (maker_note.FromBytes(maker_note_buffer, tiff_header.OffsetToZerothIFD, tiff_header.LittleEndian) == true)
                        {
                            return(IntegerValue(maker_note, Exif_MakerNote_Nikon3_ShutterCount));
                        }
                    }
                }
            }

            return(0);
        }
Ejemplo n.º 2
0
        public string SerialNumber()
        {
            string return_value = StringValue(Exif_Photo_BodySerialNumber);

            if (string.IsNullOrEmpty(return_value) == false)
            {
                return(return_value);
            }

            // See if we can pull the data from a makernote.

            string make = Make().ToLowerInvariant();

            if (make.Contains("nikon") == true && ExifIFD != null)
            {
                // Find the maker note...

                InteroperabilityField maker_note_field = ExifIFD.GetTag(MakerNote);

                if (maker_note_field != null)
                {
                    byte[] maker_note_buffer = new byte[maker_note_field.Count - 10];

                    Array.Copy(TIFFData, maker_note_field.OffsetToValue + 10, maker_note_buffer, 0, maker_note_field.Count - 10);

                    TIFFHeader th = new TIFFHeader();

                    if (th.FromBytes(maker_note_buffer, 0) == true)
                    {
                        ImageFileDirectory maker_note = new ImageFileDirectory();

                        if (maker_note.FromBytes(maker_note_buffer, th.OffsetToZerothIFD, th.LittleEndian) == true)
                        {
                            // Now read from the Maker Note Buffer!

                            return_value = StringValue(maker_note, Exif_MakerNote_Nikon3_SerialNumber, maker_note_buffer);

                            if (string.IsNullOrEmpty(return_value) == true)
                            {
                                return_value = StringValue(maker_note, Exif_MakerNote_Nikon3_SerialNO, maker_note_buffer);

                                if (return_value.StartsWith("NO=") == true)
                                {
                                    return(return_value.Substring(3, return_value.Length - 3).Trim());
                                }
                            }
                        }
                    }

                    return(return_value);
                }
            }

            return(string.Empty);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This parses the given bytes as EXIF information.
        /// </summary>
        /// <param name="bytes">The bytes to parse.</param>
        /// <returns>True on success, false otherwise.</returns>
        public bool FromBytes(byte[] bytes)
        {
            if (bytes == null || bytes.Length < 16)
            {
                return(false);
            }

            // Find the Exif signature...

            int array_index = 0;

            int exif_signature_offset = -1;
            int tiff_offset           = -1;

            while (array_index < (bytes.Length - 6))
            {
                if (bytes[array_index] == 'E' &&
                    bytes[array_index + 1] == 'x' &&
                    bytes[array_index + 2] == 'i' &&
                    bytes[array_index + 3] == 'f' &&
                    bytes[array_index + 4] == 0 &&
                    bytes[array_index + 5] == 0)
                {
                    exif_signature_offset = array_index;
                    array_index           = bytes.Length; // Exit the loop
                }

                array_index++;
            }

            if (exif_signature_offset < 0)
            {
                // Let's try to find the TIFF Header

                array_index = 0;

                while (array_index < (bytes.Length - 4))
                {
                    if (((bytes[array_index] == 'M' && bytes[array_index + 1] == 'M') ||
                         (bytes[array_index] == 'I' && bytes[array_index + 1] == 'I')) &&
                        bytes[array_index + 2] == 0x00 &&
                        bytes[array_index + 3] == 0x2A)
                    {
                        exif_signature_offset = array_index;
                        array_index           = bytes.Length; // Exit the loop
                    }

                    array_index++;
                }

                if (exif_signature_offset < 0)
                {
                    // Can't find the TIFF signature either
                    return(false);
                }

                tiff_offset = exif_signature_offset;
            }
            else
            {
                tiff_offset = exif_signature_offset + 6;
            }

            if (Header.FromBytes(bytes, tiff_offset) == false)
            {
                return(false);
            }

            int tiff_data_length = bytes.Length - tiff_offset;

            if (tiff_data_length > Program.OneMegabyte)
            {
                tiff_data_length = Program.OneMegabyte;
            }

            TIFFData = new byte[tiff_data_length];

            Array.Copy(bytes, tiff_offset, TIFFData, 0, tiff_data_length);

            IFD0.FromBytes(TIFFData, Header.OffsetToZerothIFD, Header.LittleEndian);

            var exif_field = IFD0.GetTag(ExifIFDPointer);

            if (exif_field != null)
            {
                ExifIFD = new ImageFileDirectory();
                ExifIFD.InitializeExifTagNames();

                ExifIFD.FromBytes(TIFFData, exif_field.OffsetToValue, Header.LittleEndian);
            }

            var gps_field = IFD0.GetTag(GpsIFDPointer);

            if (gps_field != null)
            {
                GPSIFD = new ImageFileDirectory();
                GPSIFD.InitializeGPSTagNames();

                GPSIFD.FromBytes(TIFFData, gps_field.OffsetToValue, Header.LittleEndian);
            }

            return(true);
        }