Beispiel #1
0
        private MathEx.UFraction32 fractionBuilder(string tester)
        {
            //  Checks to see if the user has entered a valid fraction, if the user has then a fraction (MathEx.UFraction32) will be returned
            //  If it is not a valid fraction, then it will be returned empty
            bool workingValue;

            MathEx.UFraction32 fraction;
            if (tester.Contains("/"))
            {
                if (tester.Contains("/"))
                {
                    string[] parts = tester.Split('/');
                    workingValue = Int32.TryParse(parts[0], out int numerator);
                    if (workingValue)
                    {
                        workingValue = Int32.TryParse(parts[1], out int denominator);
                        if (workingValue)
                        {
                            fraction = new MathEx.UFraction32((uint)numerator, (uint)denominator);
                            return(fraction);
                        }
                    }
                }
            }
            fraction = new MathEx.UFraction32((uint)0, (uint)0);
            return(fraction);
        }
Beispiel #2
0
 /// <summary>
 /// Converts the given unsigned rational number to an array of bytes.
 /// Numbers are converted from the platform byte-order to the given byte-order.
 /// </summary>
 public static byte[] GetBytes(MathEx.UFraction32 value, ByteOrder tobyteorder)
 {
     byte[] num  = GetBytes(value.Numerator, BitConverterEx.SystemByteOrder, tobyteorder);
     byte[] den  = GetBytes(value.Denominator, BitConverterEx.SystemByteOrder, tobyteorder);
     byte[] data = new byte[8];
     Array.Copy(num, 0, data, 0, 4);
     Array.Copy(den, 0, data, 4, 4);
     return(data);
 }
Beispiel #3
0
 /// <summary>
 /// Returns an array of unsigned rational numbers converted from
 /// the given byte array.
 /// Numbers are converted from the given byte-order to platform byte-order.
 /// </summary>
 public static MathEx.UFraction32[] ToURationalArray(byte[] data, int count, ByteOrder frombyteorder)
 {
     MathEx.UFraction32[] numbers = new MathEx.UFraction32[count];
     for (uint i = 0; i < count; i++)
     {
         byte[] num = new byte[4];
         byte[] den = new byte[4];
         Array.Copy(data, i * 8, num, 0, 4);
         Array.Copy(data, i * 8 + 4, den, 0, 4);
         numbers[i].Set(ToUInt32(num, 0, frombyteorder, BitConverterEx.SystemByteOrder), ToUInt32(den, 0, frombyteorder, BitConverterEx.SystemByteOrder));
     }
     return(numbers);
 }
Beispiel #4
0
        /// <summary>
        /// Return the altitude stored in a file
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static double GetAltitudeAtFile(string fileName)
        {
            double originalAltitudeDouble = -2147483648;
            try
            {
                ImageFile image = ImageFile.FromFile(fileName);
                MathEx.UFraction32 originalAltitude;

                ExifProperty alt;
                image.Properties.TryGetValue(ExifTag.GPSAltitude, out alt);
                originalAltitude = new MathEx.UFraction32(alt.Value.ToString());
                originalAltitudeDouble = Convert.ToDouble(originalAltitude.Numerator) / Convert.ToDouble(originalAltitude.Denominator);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return originalAltitudeDouble;
        }
 /// <summary>
 /// Returns an array of unsigned rational numbers converted from 
 /// the given byte array.
 /// Numbers are converted from the given byte-order to platform byte-order.
 /// </summary>
 public static MathEx.UFraction32[] ToURationalArray(byte[] data, int count, ByteOrder frombyteorder)
 {
     MathEx.UFraction32[] numbers = new MathEx.UFraction32[count];
     for (uint i = 0; i < count; i++)
     {
         byte[] num = new byte[4];
         byte[] den = new byte[4];
         Array.Copy(data, i * 8, num, 0, 4);
         Array.Copy(data, i * 8 + 4, den, 0, 4);
         numbers[i].Set(ToUInt32(num, 0, frombyteorder, ByteOrder.System), ToUInt32(den, 0, frombyteorder, ByteOrder.System));
     }
     return numbers;
 }
 public ExifURational(ExifTag tag, MathEx.UFraction32 value)
     : base(tag)
 {
     mValue = value;
 }
 public ExifURational(ExifTag tag, uint numerator, uint denominator)
     : base(tag)
 {
     mValue = new MathEx.UFraction32(numerator, denominator);
 }
 public ExifURational(ExifTag tag, MathEx.UFraction32 value)
     : base(tag)
 {
     mValue = value;
 }
 public ExifURational(ExifTag tag, uint numerator, uint denominator)
     : base(tag)
 {
     mValue = new MathEx.UFraction32(numerator, denominator);
 }
Beispiel #10
0
        private void save_Click(object sender, EventArgs e)
        {
            if (photoShowing != true)
            {
                loadPicture();
            }
            else
            {
                // Gets the values form the text fields
                var      picture = ImageFile.FromFile(filePaths[currentPhoto]);
                string[] data    = setValues();



                // Checks to see if the user entered a valid number and sets it accordingly
                bool   workingValue;
                string tester;
                // If the fractionBuilder returns this exact value, then the fraction is not possible
                MathEx.UFraction32 testFraction    = new MathEx.UFraction32(0, 0);
                MathEx.UFraction32 fractionStorage = new MathEx.UFraction32(0, 0); // Used to store fraction values


                // Date and time
                workingValue = DateTime.TryParse(data[0], out DateTime dateTime);
                if (workingValue)
                {
                    if (picture.Properties[ExifTag.DateTime] != null)
                    {
                        picture.Properties[ExifTag.DateTime].Value = dateTime;
                    }
                }


                //ISO
                workingValue = Int32.TryParse(data[1], out int ISO);
                if (workingValue)
                {
                    if (picture.Properties[ExifTag.ISOSpeedRatings] != null)
                    {
                        picture.Properties[ExifTag.ISOSpeedRatings].Value = (ushort)ISO;
                    }
                }


                // Aperture
                fractionStorage = fractionBuilder(data[2]);
                if (fractionStorage != testFraction)
                {
                    if (picture.Properties[ExifTag.ApertureValue] != null)
                    {
                        picture.Properties[ExifTag.ApertureValue].Value = fractionStorage;
                    }
                }


                //Exposure time
                fractionStorage = fractionBuilder(data[3]);
                if (fractionStorage != testFraction)
                {
                    if (picture.Properties[ExifTag.ExposureTime] != null)
                    {
                        picture.Properties[ExifTag.ExposureTime].Value = fractionStorage;
                    }
                }


                // Focal length
                fractionStorage = fractionBuilder(data[4]);
                if (fractionStorage != testFraction)
                {
                    if (picture.Properties[ExifTag.FocalLength] != null)
                    {
                        picture.Properties[ExifTag.FocalLength].Value = fractionStorage;
                    }
                }


                // Camera model
                if (picture.Properties[ExifTag.Model] != null)
                {
                    picture.Properties[ExifTag.Model].Value = data[5];
                }


                // Camera manufacturer
                if (picture.Properties[ExifTag.Make] != null)
                {
                    picture.Properties[ExifTag.Make].Value = data[6];
                }


                // Flash
                tester = data[7];
                if (picture.Properties[ExifTag.Flash] != null)
                {
                    if (tester == "AutoMode")
                    {
                        picture.Properties[ExifTag.Flash].Value = Flash.AutoMode;
                    }
                    else if (tester == "CompulsoryFlashMode")
                    {
                        picture.Properties[ExifTag.Flash].Value = Flash.CompulsoryFlashMode;
                    }
                    else if (tester == "FlashDidNotFire")
                    {
                        picture.Properties[ExifTag.Flash].Value = Flash.FlashDidNotFire;
                    }
                    else if (tester == "FlashFirede")
                    {
                        picture.Properties[ExifTag.Flash].Value = Flash.FlashFired;
                    }
                    else if (tester == "NoFlashFunction")
                    {
                        picture.Properties[ExifTag.Flash].Value = Flash.NoFlashFunction;
                    }
                    else if (tester == "RedEyeReductionMode")
                    {
                        picture.Properties[ExifTag.Flash].Value = Flash.RedEyeReductionMode;
                    }
                    else if (tester == "StrobeReturnLightDetected")
                    {
                        picture.Properties[ExifTag.Flash].Value = Flash.StrobeReturnLightDetected;
                    }
                    else if (tester == "StrobeReturnLightNotDetected")
                    {
                        picture.Properties[ExifTag.Flash].Value = Flash.StrobeReturnLightNotDetected;
                    }
                    else
                    {
                    }
                }


                // Lens model
                if (picture.Properties[ExifTag.LensModel] != null)
                {
                    picture.Properties[ExifTag.LensModel].Value = data[8];
                }


                // Copy right information
                if (picture.Properties[ExifTag.Copyright] != null)
                {
                    picture.Properties[ExifTag.Copyright].Value = data[9];
                }



                // This stores the photo in the edited images folder
                string newLocation = pictureFolderLocation + @"\Edited_Images\";

                if (!Directory.Exists(newLocation)) // Creates the folder if it is not there
                {
                    back.Text = "Not found";
                    Directory.CreateDirectory(newLocation);
                }

                newLocation = newLocation + metadata[11];
                picture.Save(newLocation);


                // clena up code
                // check over all of the programs code *****************
                // beta test it
                // fix bete testing bugs
                // do the guthib file experment
                // make a weite up using the github readme thing
                // figure out how to compile it over CMD
                // remove ucelsss packages
                // test compile it on moms computer
                // compile it
                // upload this and a link to the precompiled edition to my github
            }
        }
Beispiel #11
0
        /// <summary>
        /// Return the focal lenght stored in a file
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static double GetFocalLenghtAtFile(string fileName)
        {
            double originalFocalLenghtDouble = -2147483648;
            try
            {
                ImageFile image = ImageFile.FromFile(fileName);
                MathEx.UFraction32 originalFocalLenght;

                ExifProperty focal;
                image.Properties.TryGetValue(ExifTag.FocalLength, out focal);
                originalFocalLenght = new MathEx.UFraction32(focal.Value.ToString());
                originalFocalLenghtDouble = Convert.ToDouble(originalFocalLenght.Numerator) / Convert.ToDouble(originalFocalLenght.Denominator);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return originalFocalLenghtDouble;
        }