private decimal ReadGPSCoordinates(ExifTagName property)
        {
            if (IsPropertyDefined(property))
            {
                byte[] data     = GetProperty(property, null);
                byte[] intnum   = new byte[4];
                byte[] intdenom = new byte[4];
                Array.ConstrainedCopy(data, 0, intnum, 0, 4);
                Array.ConstrainedCopy(data, 4, intdenom, 0, 4);
                ExifRational deg = new ExifRational(convertToInt32(intnum), convertToInt32(intdenom));

                Array.ConstrainedCopy(data, 8, intnum, 0, 4);
                Array.ConstrainedCopy(data, 12, intdenom, 0, 4);
                ExifRational min = new ExifRational(convertToInt32(intnum), convertToInt32(intdenom));

                Array.ConstrainedCopy(data, 16, intnum, 0, 4);
                Array.ConstrainedCopy(data, 20, intdenom, 0, 4);
                ExifRational sec = new ExifRational(convertToInt32(intnum), convertToInt32(intdenom));

                decimal coord = (decimal)(deg.ToInt32() + (decimal)(min.ToFloat() / 60) + (decimal)(sec.ToFloat() / 3600));
                return(coord);
            }
            else
            {
                return(decimal.Zero);
            }
        }
Example #2
0
        private ExifRational ParseRationalValue(byte[] data)
        {
            byte[] nom = new byte[4], den = new byte[4];
            Array.Copy(data, 0, nom, 0, 4);
            Array.Copy(data, 4, den, 0, 4);

            ExifRational rat = new ExifRational();

            rat.Denominator = this.ParseIntValue(den);
            rat.Numerator   = this.ParseIntValue(nom);
            return(rat);
        }
Example #3
0
        public string GetProperty(int propertyID)
        {
            if (this.disposed)
            {
                throw new ObjectDisposedException("ExifMetadata");
            }
            if (this.IsPropertyDefined(propertyID))
            {
                PropertyItem prop = this.image.Image.GetPropertyItem(propertyID);
                if (prop.Type == 0x1)
                {
                    //1 = BYTE An 8-bit unsigned integer.,
                    return(prop.Value[0].ToString());
                }
                else if (prop.Type == 0x2)
                {
                    //2 = ASCII An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.,
                    return(GetPropertyStringASCII(propertyID, ""));
                }
                else if (prop.Type == 0x3)
                {
                    //3 = SHORT A 16-bit (2 -byte) unsigned integer,
                    return(GetPropertyShort(propertyID, 0).ToString());
                }
                else if (prop.Type == 0x4)
                {
                    //4 = LONG A 32-bit (4 -byte) unsigned integer,
                    return(GetPropertyInt(propertyID, 0).ToString());
                }
                else if (prop.Type == 0x5)
                {
                    //5 = RATIONAL Two LONGs. The first LONG is the numerator and the second LONG expresses the//denominator.,
                    return(GetPropertyRational(propertyID).ToString("."));
                }
                else if (prop.Type == 0x7)
                {
                    //7 = UNDEFINED An 8-bit byte that can take any value depending on the field definition,
                    return(prop.Value[0].ToString());
                }
                else if (prop.Type == 0x9)
                {
                    //9 = SLONG A 32-bit (4 -byte) signed integer (2's complement notation),
                    return(convertToInt32(prop.Value).ToString());
                }
                else if (prop.Type == 0xA)
                {
                    //10 = SRATIONAL Two SLONGs. The first SLONG is the numerator and the second SLONG is the
                    //denominator.

                    // rational
                    byte[] n = new byte[prop.Len / 2];
                    byte[] d = new byte[prop.Len / 2];
                    Array.Copy(prop.Value, 0, n, 0, prop.Len / 2);
                    Array.Copy(prop.Value, prop.Len / 2, d, 0, prop.Len / 2);
                    int          a = convertToInt32(n);
                    int          b = convertToInt32(d);
                    ExifRational r = new ExifRational(a, b);
                    r.ToString(".");
                }
            }
            return(string.Empty);
        }