Пример #1
0
        /// <summary>
        /// Calculates the floating point value of this IFD.
        /// </summary>
        /// <returns>The value of this IFD as a float.</returns>
        public double AsDecimal()
        {
            int numerator   = TIFFHeader.ToInt32(Buffer, OffsetToValue, IsLittleEndian);
            int denominator = TIFFHeader.ToInt32(Buffer, OffsetToValue + 4, IsLittleEndian);

            return(Exif.Rational(numerator, denominator));
        }
Пример #2
0
        static void ProcessFile(string this_file_to_process, int file_number)
        {
            int buffer_size = BufferSize;

            var file_information = new FileInfo(this_file_to_process);

            if (file_information.Length < buffer_size)
            {
                buffer_size = (int)file_information.Length;
            }

            byte[] buffer = new byte[buffer_size];

            int number_of_bytes_read = 0;

            try
            {
                using (var input_stream = File.OpenRead(this_file_to_process))
                {
                    number_of_bytes_read = input_stream.Read(buffer, 0, buffer.Length);
                }
            }
            catch (Exception)
            {
                number_of_bytes_read = 0;
            }

            if (number_of_bytes_read > 0)
            {
                var exif_data = new Exif();

                string filename_extension = System.IO.Path.GetExtension(this_file_to_process);

                if (exif_data.FromBytes(buffer) == true)
                {
                    int final_field = exif_data.ShutterCount();

                    if (final_field == 0)
                    {
                        final_field = exif_data.SequenceNumber();
                    }

                    if (final_field == 0)
                    {
                        final_field = file_number;
                    }

                    var taken = exif_data.Taken();

                    string new_filename  = string.Format("{0}_{1}{2}", taken.ToString("yyyyMMdd_HHmmss", System.Globalization.CultureInfo.InvariantCulture), final_field, filename_extension);
                    string just_filename = System.IO.Path.GetFileName(this_file_to_process);

                    if (string.Compare(new_filename, just_filename) != 0)
                    {
                        string rename_to = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this_file_to_process), new_filename);
                        System.IO.File.Move(this_file_to_process, rename_to);
                    }
                }
            }
        }
Пример #3
0
        static void ProcessFile(string this_file_to_process, string output_directory)
        {
            int buffer_size = BufferSize;

            try
            {
                var file_information = new FileInfo(this_file_to_process);

                if (file_information.Length < buffer_size)
                {
                    buffer_size = (int)file_information.Length;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            byte[] buffer = new byte[buffer_size];

            int number_of_bytes_read = 0;

            try
            {
                using (var input_stream = File.OpenRead(this_file_to_process))
                {
                    number_of_bytes_read = input_stream.Read(buffer, 0, buffer.Length);
                }
            }
            catch (Exception)
            {
                number_of_bytes_read = 0;
            }

            if (number_of_bytes_read > 0)
            {
                var exif_data = new Exif();

                string filename_extension = System.IO.Path.GetExtension(this_file_to_process);

                if (exif_data.FromBytes(buffer) == true)
                {
                    int final_field = exif_data.ShutterCount();

                    if (final_field == 0)
                    {
                        final_field = exif_data.SequenceNumber();
                    }

                    try
                    {
                        var taken = exif_data.Taken();

                        // Create year path
                        string directoryName = output_directory + "\\" + taken.ToString("yyyy", System.Globalization.CultureInfo.InvariantCulture);
                        Directory.CreateDirectory(directoryName);
                        // Create month path
                        directoryName = directoryName + "\\" + taken.ToString("yyyy-MM-MMMM", System.Globalization.CultureInfo.InvariantCulture);
                        // Create day-where path
                        directoryName = directoryName + "\\" + taken.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                        Directory.CreateDirectory(directoryName);

                        long length = new System.IO.FileInfo(this_file_to_process).Length;

                        string new_filename = string.Format("{0}-{1}{2}",
                                                            taken.ToString("yyyy-MM-dd-hh-mm-ss", System.Globalization.CultureInfo.InvariantCulture), length,
                                                            filename_extension);

                        string rename_to = System.IO.Path.Combine(directoryName, new_filename);

                        CreateSymbolicLink(rename_to, this_file_to_process, SymbolicLink.File);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return;
                    }
                }
            }
        }