예제 #1
0
 /// <summary>
 /// Creates a new instance of the ExifReader class initialized with the specified PropertyItem array.
 /// </summary>
 /// <param name="oPropertyItems">Specifies an array of property items to read from.</param>
 public ExifReader(PropertyItem[] oPropertyItems)
 {
     if (oPropertyItems != null)
         m_oPropertyItems = oPropertyItems;
     else
         throw new ArgumentNullException("oPropertyItems", "The specified parameter cannot be null.");
 }
예제 #2
0
        internal static PropertyItem[] ConvertFromMemory(IntPtr propdata, int count) {
            PropertyItem[] props = new PropertyItem[count];

            for (int i=0; i<count; i++) {
                PropertyItemInternal propcopy = null;
                try {
                    propcopy = (PropertyItemInternal) UnsafeNativeMethods.PtrToStructure(propdata,
                                                  typeof(PropertyItemInternal));

                    props[i] = new PropertyItem();
                    props[i].Id = propcopy.id;
                    props[i].Len = propcopy.len;
                    props[i].Type = propcopy.type;

                    // this calls Marshal.Copy and creates a copy of the original memory into a byte array.
                    props[i].Value = propcopy.Value;
                    
                    propcopy.value = IntPtr.Zero;  // we dont actually own this memory so dont free it.
                }
                finally {
                    if (propcopy != null) {
                        propcopy.Dispose();
                    }
                }
                
				propdata = (IntPtr)((long)propdata + (int)Marshal.SizeOf(typeof(PropertyItemInternal)));
            }

            return props;
        }
예제 #3
0
        /// <summary>
        /// Returns the first PropertyItem with a matching ID
        /// </summary>
        /// <param name="items"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        protected static PropertyItem getById(PropertyItem[] items, int id)
        {
            for (int i = 0; i < items.Length; i++)
               if (items[i] != null && items[i].Id == id)
                   return items[i];

              return null;
        }
예제 #4
0
        public ExifProperty(PropertyItem propertyItem)
        {
            if (propertyItem == null) throw new ArgumentNullException("propertyItem");
            item = propertyItem;

            CreateTag();
            CreateValue();
        }
예제 #5
0
 protected static int GetLoops(PropertyItem[] items)
 {
     // http://weblogs.asp.net/justin_rogers/archive/2004/01/19/60424.aspx
       //Property item ID 20737
       PropertyItem pi = getById(items, 20737);
       if (pi == null) return 0;
       //Combine bytes into integers
       return pi.Value[0] + (pi.Value[1] << 8);
 }
예제 #6
0
 /// <summary>
 /// 以原始形式设置指定的属性
 /// </summary>
 /// <param name="PID"></param>
 /// <param name="Data"></param>
 /// <param name="Type"></param>
 private void SetProperty(Int32 PID, byte[] Data, ExifDataTypes Type)
 {
     System.Drawing.Imaging.PropertyItem P = this._Image.PropertyItems[0];
     P.Id    = PID;
     P.Value = Data;
     P.Type  = (Int16)Type;
     P.Len   = Data.Length;
     this._Image.SetPropertyItem(P);
 }
예제 #7
0
		public static void SaveThumbnail(Image thumb, ushort rating, string filePath)
		{
			string thumbPath = GetThumbPath(filePath);
			if (ratingProperty == null)
			{
				System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ThumbUtility));
				ratingProperty = ((System.Drawing.Image)(resources.GetObject("rating"))).GetPropertyItem(18246);
			}
			ratingProperty.Value = BitConverter.GetBytes(rating);
			thumb.SetPropertyItem(ratingProperty);
			thumb.Save(thumbPath, ImageFormat.Jpeg);
		}
예제 #8
0
        // funzione utilizzata per l'estrazione dei metadati
        private static double DecodeRational64u(System.Drawing.Imaging.PropertyItem propertyItem)
        {
            uint dN = BitConverter.ToUInt32(propertyItem.Value, 0);
            uint dD = BitConverter.ToUInt32(propertyItem.Value, 4);
            uint mN = BitConverter.ToUInt32(propertyItem.Value, 8);
            uint mD = BitConverter.ToUInt32(propertyItem.Value, 12);
            uint sN = BitConverter.ToUInt32(propertyItem.Value, 16);
            uint sD = BitConverter.ToUInt32(propertyItem.Value, 20);

            decimal deg;
            decimal min;
            decimal sec;

            if (dD > 0)
            {
                deg = (decimal)dN / dD;
            }
            else
            {
                deg = dN;
            }
            if (mD > 0)
            {
                min = (decimal)mN / mD;
            }
            else
            {
                min = mN;
            }
            if (sD > 0)
            {
                sec = (decimal)sN / sD;
            }
            else
            {
                sec = sN;
            }

            double deg1 = (double)deg;
            double min1 = (double)min;
            double sec1 = (double)sec;

            if (sec == 0)
            {
                double conversion = ConvertDegreeAngleToDouble(deg1, min1, sec1);
                return(conversion);
            }
            else
            {
                double conversion = ConvertDegreeAngleToDouble(deg1, min1, sec1);
                return(conversion);
            }
        }
예제 #9
0
 protected static int[] GetDelays(PropertyItem[] items)
 {
     //Property item ID 20736 http://bytes.com/groups/net-vb/692099-problem-animated-gifs
       PropertyItem pi = getById(items, 20736);
       if (pi == null) return null;
       //Combine bytes into integers
       int[] vals = new int[pi.Value.Length / 4];
       for (int i = 0; i < pi.Value.Length; i+=4){
           vals[i / 4] = BitConverter.ToInt32(pi.Value, i);
       }
       return vals;
 }
예제 #10
0
        public static void SetPropertyItems(Image image, PropertyItem[] items)
        {
            PropertyItem[] pis = image.PropertyItems;

            foreach (PropertyItem pi in pis)
            {
                image.RemovePropertyItem(pi.Id);
            }

            foreach (PropertyItem pi in items)
            {
                image.SetPropertyItem(pi);
            }
        }
예제 #11
0
        public static void LoadProperties(Image dstImage, Document srcDoc, Func <System.Drawing.Imaging.PropertyItem, bool> selectorFn)
        {
            Bitmap bitmap = dstImage as Bitmap;

            if (bitmap != null)
            {
                float dpuX;
                float dpuY;
                switch (srcDoc.DpuUnit)
                {
                case MeasurementUnit.Inch:
                    dpuX = (float)srcDoc.DpuX;
                    dpuY = (float)srcDoc.DpuY;
                    break;

                case MeasurementUnit.Centimeter:
                    dpuX = (float)Document.DotsPerCmToDotsPerInch(srcDoc.DpuX);
                    dpuY = (float)Document.DotsPerCmToDotsPerInch(srcDoc.DpuY);
                    break;

                default:
                    dpuX = 1f;
                    dpuY = 1f;
                    break;
                }
                try
                {
                    bitmap.SetResolution(dpuX, dpuY);
                }
                catch (Exception)
                {
                }
            }
            Metadata metadata = srcDoc.Metadata;

            foreach (string str in metadata.GetKeys("$exif"))
            {
                System.Drawing.Imaging.PropertyItem arg = PdnGraphics.DeserializePropertyItem(metadata.GetValue("$exif", str));
                if (selectorFn(arg))
                {
                    try
                    {
                        dstImage.SetPropertyItem(arg);
                    }
                    catch (ArgumentException)
                    {
                    }
                }
            }
        }
예제 #12
0
        //My SetProperty code... (for ASCII property items only!)
        //Exif 2.2 requires that ASCII property items terminate with a null (0x00).
        private static void SetProperty(ref System.Drawing.Imaging.PropertyItem prop, int iId, string sTxt)
        {
            int iLen = sTxt.Length + 1;

            byte[] bTxt = new Byte[iLen];
            for (int i = 0; i < iLen - 1; i++)
            {
                bTxt[i] = (byte)sTxt[i];
            }
            bTxt[iLen - 1] = 0x00;
            prop.Id        = iId;
            prop.Type      = 2;
            prop.Value     = bTxt;
            prop.Len       = iLen;
        }
 public static PropertyItem GetPropertyItem(int id, string value)
 {
     if (propertyItem == null)
     {
         System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PropertyItemProvider));
         Bitmap bmp = (Bitmap)resources.GetObject("propertyitemcontainer");
         propertyItem = bmp.GetPropertyItem(bmp.PropertyIdList[0]);
         propertyItem.Type = 2; // string
     }
     propertyItem.Id = id;
     System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
     propertyItem.Value = encoding.GetBytes(value + " ");
     propertyItem.Len = value.Length + 1;
     return propertyItem;
 }
예제 #14
0
파일: Exif.cs 프로젝트: metadeta96/openpdn
        public static string DecodeAsciiValue(PropertyItem pi)
        {
            if (pi.Type != (short)ExifTagType.Ascii)
            {
                throw new ArgumentException("pi.Type != ExifTagType.Ascii");
            }
            
            string data = System.Text.Encoding.ASCII.GetString(pi.Value);
            if (data[data.Length - 1] == '\0')
            {
                data = data.Substring(0, data.Length - 1);
            }

            return data;
        }
예제 #15
0
        private static string DecodeRational64u(System.Drawing.Imaging.PropertyItem propertyItem)
        {
            uint dN = BitConverter.ToUInt32(propertyItem.Value, 0);
            uint dD = BitConverter.ToUInt32(propertyItem.Value, 4);
            uint mN = BitConverter.ToUInt32(propertyItem.Value, 8);
            uint mD = BitConverter.ToUInt32(propertyItem.Value, 12);
            uint sN = BitConverter.ToUInt32(propertyItem.Value, 16);
            uint sD = BitConverter.ToUInt32(propertyItem.Value, 20);

            decimal deg;
            decimal min;
            decimal sec;

            // Found some examples where you could get a zero denominator and no one likes to devide by zero
            if (dD > 0)
            {
                deg = (decimal)dN / dD;
            }
            else
            {
                deg = dN;
            }
            if (mD > 0)
            {
                min = (decimal)mN / mD;
            }
            else
            {
                min = mN;
            }
            if (sD > 0)
            {
                sec = (decimal)sN / sD;
            }
            else
            {
                sec = sN;
            }

            if (sec == 0)
            {
                return(string.Format("{0}° {1:0.###}'", deg, min));
            }
            else
            {
                return(string.Format("{0}° {1:0}' {2:0.#}\"", deg, min, sec));
            }
        }
예제 #16
0
        internal static PropertyItemInternal ConvertFromPropertyItem(PropertyItem propItem) {
            PropertyItemInternal propItemInternal = new PropertyItemInternal();
            propItemInternal.id = propItem.Id;
            propItemInternal.len = 0;
            propItemInternal.type = propItem.Type;

            byte[] propItemValue = propItem.Value;
            if (propItemValue != null) {
                int length = propItemValue.Length;
                propItemInternal.len = length;
                propItemInternal.value = Marshal.AllocHGlobal(length);
                Marshal.Copy(propItemValue, 0, propItemInternal.value, length);
            }

            return propItemInternal;
        }
예제 #17
0
        /// <summary>
        /// Copies the given PropertyItem.
        /// </summary>
        /// <param name="pi">The PropertyItem to clone.</param>
        /// <returns>A copy of the given PropertyItem.</returns>
        public static PropertyItem ClonePropertyItem(PropertyItem pi)
        {
            byte[] valueClone;

            if (pi.Value == null)
            {
                valueClone = new byte[0];
            }
            else
            {
                valueClone = (byte[])pi.Value.Clone();
            }

            PropertyItem2 pi2 = new PropertyItem2(pi.Id, pi.Len, pi.Type, valueClone);
            return pi2.ToPropertyItem();
        }
 internal static PropertyItemInternal ConvertFromPropertyItem(PropertyItem propItem)
 {
     PropertyItemInternal internal2 = new PropertyItemInternal {
         id = propItem.Id,
         len = 0,
         type = propItem.Type
     };
     byte[] source = propItem.Value;
     if (source != null)
     {
         int length = source.Length;
         internal2.len = length;
         internal2.value = Marshal.AllocHGlobal(length);
         Marshal.Copy(source, 0, internal2.value, length);
     }
     return internal2;
 }
예제 #19
0
        private static GeoCoords DecodeRational64U(System.Drawing.Imaging.PropertyItem propertyItem)
        {
            var dN = BitConverter.ToUInt32(propertyItem.Value, 0);
            var dD = BitConverter.ToUInt32(propertyItem.Value, 4);
            var mN = BitConverter.ToUInt32(propertyItem.Value, 8);
            var mD = BitConverter.ToUInt32(propertyItem.Value, 12);
            var sN = BitConverter.ToUInt32(propertyItem.Value, 16);
            var sD = BitConverter.ToUInt32(propertyItem.Value, 20);

            double deg;
            double min;
            double sec;

            if (dD > 0)
            {
                deg = (double)dN / dD;
            }
            else
            {
                deg = dN;
            }
            if (mD > 0)
            {
                min = (double)mN / mD;
            }
            else
            {
                min = mN;
            }
            if (sD > 0)
            {
                sec = (double)sN / sD;
            }
            else
            {
                sec = sN;
            }

            return(new GeoCoords
            {
                Degree = deg,
                Minute = min,
                Second = sec
            });
        }
예제 #20
0
        /// <summary>
        /// Initializes a new instance of the ExifProperty class.
        /// It's marked internal  as it's not intended to be instantiated independently outside of the library.
        /// </summary>
        /// <param name="propertyItem">The PropertyItem to base the object on</param>
        /// <param name="parentReader">The parent ExifReader</param>
        internal ExifProperty(PropertyItem propertyItem, ExifReader parentReader)
        {
            this.parentReader = parentReader;
            this.propertyItem = propertyItem;
            this.isUnknown = !Enum.IsDefined(typeof(PropertyTagId), this.RawExifTagId);

            var customFormatter = this.parentReader.QueryForCustomPropertyFormatter(this.RawExifTagId);

            if (customFormatter == null)
            {
                this.propertyFormatter = ExifPropertyFormatterProvider.GetExifPropertyFormatter(this.ExifTag);
            }
            else
            {
                this.propertyFormatter = customFormatter;
                this.hasCustomFormatter = true;
            }
        }
예제 #21
0
 /************************************************************************
  * The Input: a path to an image.
  * The Output: The datetime.
  * The Function operation: The function finds the image's datetime.
  *************************************************************************/
 public static DateTime GetDateTakenFromImage(string path)
 {
     using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
         using (Image myImage = Image.FromStream(fs, false, false))
         {
             try
             {
                 System.Drawing.Imaging.PropertyItem propItem = myImage.GetPropertyItem(36867);
                 string dateTaken = r.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2);
                 return(DateTime.Parse(dateTaken));
             }
             catch
             {
                 //Incase the image doesn't have a date return the files date.
                 return(File.GetCreationTime(path));
             }
         }
 }
 internal static PropertyItem[] ConvertFromMemory(IntPtr propdata, int count)
 {
     PropertyItem[] itemArray = new PropertyItem[count];
     for (int i = 0; i < count; i++)
     {
         using (PropertyItemInternal internal2 = null)
         {
             internal2 = (PropertyItemInternal) UnsafeNativeMethods.PtrToStructure(propdata, typeof(PropertyItemInternal));
             itemArray[i] = new PropertyItem();
             itemArray[i].Id = internal2.id;
             itemArray[i].Len = internal2.len;
             itemArray[i].Type = internal2.type;
             itemArray[i].Value = internal2.Value;
             internal2.value = IntPtr.Zero;
         }
         propdata = (IntPtr) (((long) propdata) + Marshal.SizeOf(typeof(PropertyItemInternal)));
     }
     return itemArray;
 }
예제 #23
0
파일: Exif.cs 프로젝트: metadeta96/openpdn
        public static byte DecodeByteValue(PropertyItem pi)
        {
            if (pi.Type != (short)ExifTagType.Byte)
            {
                throw new ArgumentException("pi.Type != ExifTagType.Byte");
            }

            if (pi.Value.Length != 1)
            {
                throw new ArgumentException("pi.Value.Length != 1");
            }

            if (pi.Len != 1)
            {
                throw new ArgumentException("pi.Length != 1");
            }

            return pi.Value[0];
        }
예제 #24
0
 private static string GetValueOfType(PropertyItem propItem)
 {
     switch (propItem.Type)
     {
     case 1:
         return EXIFMetaDataService.GetValueOfType1(propItem.Value);
     case 2:
         return EXIFMetaDataService.GetValueOfType2(propItem.Value);
     case 3:
         return EXIFMetaDataService.GetValueOfType3(propItem.Value);
     case 4:
         return EXIFMetaDataService.GetValueOfType4(propItem.Value);
     case 5:
         return EXIFMetaDataService.GetValueOfType5(propItem.Value);
     case 7:
         return EXIFMetaDataService.GetValueOfType7(propItem.Value, propItem.Id);
     }
     return string.Empty;
 }
예제 #25
0
        private static decimal DecodeRational64uTest(System.Drawing.Imaging.PropertyItem propertyItem)
        {
            uint dN = BitConverter.ToUInt32(propertyItem.Value, 0);
            uint dD = BitConverter.ToUInt32(propertyItem.Value, 4);
            uint mN = BitConverter.ToUInt32(propertyItem.Value, 8);
            uint mD = BitConverter.ToUInt32(propertyItem.Value, 12);
            uint sN = BitConverter.ToUInt32(propertyItem.Value, 16);
            uint sD = BitConverter.ToUInt32(propertyItem.Value, 20);

            decimal deg;
            decimal min;
            decimal sec;

            // Found some examples where you could get a zero denominator and no one likes to devide by zero
            if (dD > 0)
            {
                deg = (decimal)dN / dD;
            }
            else
            {
                deg = dN;
            }
            if (mD > 0)
            {
                min = (decimal)mN / mD;
            }
            else
            {
                min = mN;
            }
            if (sD > 0)
            {
                sec = (decimal)sN / sD;
            }
            else
            {
                sec = sN;
            }

            // Decimal Degrees = Degrees + minutes / 60 + seconds / 3600
            return(deg + min / 60 + sec / 3600);
        }
예제 #26
0
        private DateTime getExifDateTaken(string path)
        {
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                using (Image myImage = Image.FromStream(fs, false, false))
                {
                    System.Drawing.Imaging.PropertyItem propertyItem = myImage.GetPropertyItem(36867);
                    if (propertyItem != null)
                    {
                        // Extract the property value as a String.
                        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                        string text = encoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1);

                        // Parse the date and time.
                        System.Globalization.CultureInfo provider = CultureInfo.InvariantCulture;
                        DateTime dateCreated = DateTime.ParseExact(text, "yyyy:MM:d H:m:s", provider);
                        return(dateCreated);
                    }
                    return(new DateTime());
                }
        }
예제 #27
0
        /// <summary>
        /// Obtiene la propiedad EXIF de la imagen
        /// </summary>
        /// <param name="bmp">Objeto imagen</param>
        /// <param name="propertyType">Propiedad que se quiere obtener</param>
        /// <returns>Valor de la propiedad</returns>
        public static string GetPropiedadImage(Bitmap bmp, ImagePropertyIDTags propertyType)
        {
            string result = null;

            try
            {
                System.Drawing.Imaging.PropertyItem item = bmp.GetPropertyItem((int)propertyType);
                object value = Images.GetPropertyImageValue(item);

                if (value != null)
                {
                    result = value.ToString();
                }
            }
            catch (Exception ex)
            {
                //   throw ex;
            }

            return(result);
        }
예제 #28
0
 private void SetPropertyValue(Image bmp, int ID, short Type, byte[] value)
 {
     foreach (PropertyItem item in bmp.PropertyItems)
     {
         if (item.Id == ID)
         {
             item.Type  = Type;
             item.Value = value;
             item.Len   = value.Length;
             bmp.SetPropertyItem(item);
             return;
         }
     }
     System.Drawing.Imaging.PropertyItem p1 = _headerSeed.PropertyItems[0];
     // 緯度
     p1.Id    = ID;
     p1.Type  = Type;
     p1.Value = value;
     p1.Len   = value.Length;
     bmp.SetPropertyItem(p1);
 }
예제 #29
0
        /// <summary>
        /// Establece el valor de la propiedad EXIF de la imagen
        /// </summary>
        /// <param name="bmp">Objeto imagen</param>
        /// <param name="propertyType">Propiedad que se quiere modificar</param>
        /// <param name="value">Valor de la propiedad</param>
        /// <returns>Objeto imagen</returns>
        public static Bitmap SetPropiedadImage(Bitmap bmp, ImagePropertyIDTags propertyType, String value)
        {
            System.Drawing.Imaging.PropertyItem item = null;
            try
            {
                item = bmp.GetPropertyItem((int)propertyType);
            }
            catch (Exception ex)
            {
                item = Images.createPropertyItem();
            }

            switch (propertyType)
            {
            case ImagePropertyIDTags.GpsLongitude:
            case ImagePropertyIDTags.GpsLatitude:
                string[] values = value.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                item.Type  = (short)PropertyTagType.SRational;
                item.Value = new byte[24];

                item.Value[0]  = Convert.ToByte(Convert.ToInt32(values[0]));
                item.Value[4]  = 1;
                item.Value[8]  = Convert.ToByte(Convert.ToInt32(values[1]));
                item.Value[12] = 1;
                item.Value[16] = Convert.ToByte(Convert.ToInt32(values[2]));
                item.Value[20] = 1;
                break;

            default:
                item.Type  = (short)PropertyTagType.ASCII;
                item.Value = System.Text.Encoding.ASCII.GetBytes(value);
                break;
            }
            item.Id  = (int)propertyType;
            item.Len = item.Value.Length;
            bmp.SetPropertyItem(item);

            return(bmp);
        }
예제 #30
0
        public static String GetImageDate(string filePath, string datetype = "datetime")
        {
            System.Drawing.Image myImage = Image.FromFile(filePath);
            String date = "  ";

            try
            {
                System.Drawing.Imaging.PropertyItem propItem = myImage.GetPropertyItem(36867);
                string dateTaken = new System.Text.RegularExpressions.Regex(":").Replace(System.Text.Encoding.UTF8.GetString(propItem.Value), "-", 2);
                Console.WriteLine(datetype);

                if (datetype == "datetime")
                {
                    date = System.DateTime.Parse(dateTaken).ToString();
                }
                else
                {
                    date = System.DateTime.Parse(dateTaken).ToShortDateString();
                }
            }
            catch (Exception e) { }

            return(date);
        }
예제 #31
0
파일: Exif.cs 프로젝트: metadeta96/openpdn
        public static void DecodeRationalValue(PropertyItem pi, out int numerator, out int denominator)
        {
            if (pi.Type != (short)ExifTagType.SRational)
            {
                throw new ArgumentException("pi.Type != ExifTagType.SRational");
            }

            if (pi.Value.Length != 8)
            {
                throw new ArgumentException("pi.Value.Length != 8");
            }

            if (pi.Len != 8)
            {
                throw new ArgumentException("pi.Length != 8");
            }

            numerator = pi.Value[0] + (pi.Value[1] << 8) + (pi.Value[2] << 16) + (pi.Value[3] << 24);
            denominator = pi.Value[4] + (pi.Value[5] << 8) + (pi.Value[6] << 16) + (pi.Value[7] << 24);
        }
예제 #32
0
파일: Exif.cs 프로젝트: metadeta96/openpdn
        public static ushort DecodeShortValue(PropertyItem pi)
        {
            if (pi.Type != (short)ExifTagType.Short)
            {
                throw new ArgumentException("pi.Type != ExifTagType.Short");
            }

            if (pi.Value.Length != 2)
            {
                throw new ArgumentException("pi.Value.Length != 2");
            }

            if (pi.Len != 2)
            {
                throw new ArgumentException("pi.Length != 2");
            }

            return (ushort)(pi.Value[0] + (pi.Value[1] << 8));
        }
예제 #33
0
파일: Exif.cs 프로젝트: metadeta96/openpdn
        public static int DecodeSLongValue(PropertyItem pi)
        {
            if (pi.Type != (short)ExifTagType.SLong)
            {
                throw new ArgumentException("pi.Type != ExifTagType.SLong");
            }

            if (pi.Value.Length != 4)
            {
                throw new ArgumentException("pi.Value.Length != 4");
            }

            if (pi.Len != 4)
            {
                throw new ArgumentException("pi.Length != 4");
            }

            return pi.Value[0] + (pi.Value[1] << 8) + (pi.Value[2] << 16) + (pi.Value[3] << 24);
        }
예제 #34
0
 public static object GetValueObject(PropertyItem property)
 {
     if (property == null)
         return null;
     switch ((PropertyTagType)property.Type)
     {
         //ASCII
         case PropertyTagType.ASCII:
             ASCIIEncoding encoding = new ASCIIEncoding();
             return encoding.GetString(property.Value, 0, property.Len - 1);
         //BYTE
         case PropertyTagType.Byte:
             if (property.Len == 1)
                 return property.Value[0];
             else
                 return property.Value;
         //LONG
         case PropertyTagType.Long:
             uint[] resultLong = new uint[property.Len / 4];
             for (int i = 0; i < resultLong.Length; i++)
                 resultLong[i] = BitConverter.ToUInt32(property.Value, i * 4);
             if (resultLong.Length == 1)
                 return resultLong[0];
             else
                 return resultLong;
         //SHORT
         case PropertyTagType.Short:
             ushort[] resultShort = new ushort[property.Len / 2];
             for (int i = 0; i < resultShort.Length; i++)
                 resultShort[i] = BitConverter.ToUInt16(property.Value, i * 2);
             if (resultShort.Length == 1)
                 return resultShort[0];
             else
                 return resultShort;
         //SLONG
         case PropertyTagType.SLONG:
             int[] resultSLong = new int[property.Len / 4];
             for (int i = 0; i < resultSLong.Length; i++)
                 resultSLong[i] = BitConverter.ToInt32(property.Value, i * 4);
             if (resultSLong.Length == 1)
                 return resultSLong[0];
             else
                 return resultSLong;
         //RATIONAL
         case PropertyTagType.Rational:
             Fraction[] resultRational = new Fraction[property.Len / 8];
             uint uNumerator;
             uint uDenumerator;
             for (int i = 0; i < resultRational.Length; i++)
             {
                 uNumerator = BitConverter.ToUInt32(property.Value, i * 8);
                 uDenumerator = BitConverter.ToUInt32(property.Value, i * 8 + 4);
                 resultRational[i] = new Fraction(uNumerator, uDenumerator);
             }
             if (resultRational.Length == 1)
                 return resultRational[0];
             else
                 return resultRational;
         //SRATIONAL
         case PropertyTagType.SRational:
             Fraction[] resultSRational = new Fraction[property.Len / 8];
             int sNumerator;
             int sDenumerator;
             for (int i = 0; i < resultSRational.Length; i++)
             {
                 sNumerator = BitConverter.ToInt32(property.Value, i * 8);
                 sDenumerator = BitConverter.ToInt32(property.Value, i * 8 + 4);
                 resultSRational[i] = new Fraction(sNumerator, sDenumerator);
             }
             if (resultSRational.Length == 1)
                 return resultSRational[0];
             else
                 return resultSRational;
         //UNDEFINE
         default:
             if (property.Len == 1)
                 return property.Value[0];
             else
                 return property.Value;
     }
 }
예제 #35
0
        /// <summary>
        /// Obtiene el valor de una propiedad
        /// </summary>
        /// <param name="item">Propiedad EXIF de la imagen</param>
        /// <returns>Devuelve el valor de la propiedad</returns>
        public static object GetPropertyImageValue(System.Drawing.Imaging.PropertyItem item)
        {
            Object propValue = new Object();

            switch ((PropertyTagType)item.Type)
            {
            case PropertyTagType.ASCII:
                ASCIIEncoding encoding = new ASCIIEncoding();
                propValue = encoding.GetString(item.Value, 0, item.Len - 1);
                break;

            case PropertyTagType.Int16:
                propValue = BitConverter.ToInt16(item.Value, 0);
                break;

            case PropertyTagType.SLONG:
            case PropertyTagType.Int32:
                propValue = BitConverter.ToInt32(item.Value, 0);
                break;

            case PropertyTagType.SRational:
            case PropertyTagType.Rational:
                uint degreesNumerator   = BitConverter.ToUInt32(item.Value, 0);
                uint degreesDenominator = BitConverter.ToUInt32(item.Value, 4);
                uint minutesNumerator   = BitConverter.ToUInt32(item.Value, 8);
                uint minutesDenominator = BitConverter.ToUInt32(item.Value, 12);
                uint secondsNumerator   = BitConverter.ToUInt32(item.Value, 16);
                uint secondsDenominator = BitConverter.ToUInt32(item.Value, 20);

                if (degreesDenominator != 0)
                {
                    propValue = ((double)degreesNumerator / (double)degreesDenominator).ToString();
                }
                else
                {
                    propValue = "0";
                }

                if (minutesDenominator != 0)
                {
                    propValue += ";" + ((double)minutesNumerator / (double)minutesDenominator).ToString();
                }
                else
                {
                    propValue = "0";
                }

                if (secondsDenominator != 0)
                {
                    propValue += ";" + ((double)secondsNumerator / (double)secondsDenominator).ToString();
                }
                else
                {
                    propValue = "0";
                }

                if (propValue.ToString() == "NaN")
                {
                    propValue = "0";
                }
                break;

            case PropertyTagType.Undefined:
                propValue = "Undefined Data";
                break;
            }

            return(propValue);
        }
예제 #36
0
 private static void CopyMetadata(PropertyItem[] properties, Image target) {
     foreach (PropertyItem property in properties) {
         try {
             target.SetPropertyItem(property);
         }
         catch (ArgumentException) {
             // just ignore it; on some configurations this fails
         }
     }
 }
예제 #37
0
 public EXIFPropertyItem(PropertyItem prop)
 {
     // Does KnownEXIFCodes have a corresponding entry?
     if (Enum.IsDefined(exifCode.GetType(), prop.Id))
     {
         exifCode = (KnownEXIFIDCodes)prop.Id;
     }
     else
     {
         exifCode = KnownEXIFIDCodes.UnknownCode;
     }
     exifType = (EXIFPropertyTypes)prop.Type;
     data = prop.Value;
     this.type = prop.Type;
     this.id = prop.Id;
     this.len = prop.Len;
 }
예제 #38
0
파일: img.cs 프로젝트: yaoshuyin/csharp
		static string PropertyTypeAndSize(PropertyItem item) {
			int	divide;

			switch((PropertyTagType)item.Type) {
				case PropertyTagType.Byte:	divide = 1; break;
				case PropertyTagType.Long:	divide = 4; break;
				case PropertyTagType.Rational:	divide = 8; break;
				case PropertyTagType.Short:	divide = 2; break;
				case PropertyTagType.SRational:	divide = 4; break;
				default:			divide = 0; break;
			}
			if ((divide != 0) && ((item.Len / divide) > 1)) {
				return String.Format("{0}[{1}]", Enum.GetName(typeof(PropertyTagType), item.Type).ToString(), item.Len / divide);
			}

			return Enum.GetName(typeof(PropertyTagType), item.Type);
		}
예제 #39
0
        private static float ExifGpsToFloat(PropertyItem propItemRef, PropertyItem propItem)
        {
            uint degreesNumerator = BitConverter.ToUInt32(propItem.Value, 0);
            uint degreesDenominator = BitConverter.ToUInt32(propItem.Value, 4);
            float degrees = degreesNumerator / (float)degreesDenominator;

            uint minutesNumerator = BitConverter.ToUInt32(propItem.Value, 8);
            uint minutesDenominator = BitConverter.ToUInt32(propItem.Value, 12);
            float minutes = minutesNumerator / (float)minutesDenominator;

            uint secondsNumerator = BitConverter.ToUInt32(propItem.Value, 16);
            uint secondsDenominator = BitConverter.ToUInt32(propItem.Value, 20);
            float seconds = secondsNumerator / (float)secondsDenominator;

            float coorditate = degrees + (minutes / 60f) + (seconds / 3600f);
            string gpsRef = System.Text.Encoding.ASCII.GetString(new byte[1] { propItemRef.Value[0] }); //N, S, E, or W
            if (gpsRef == "S" || gpsRef == "W")
                coorditate = 0 - coorditate;
            return coorditate;
        }
예제 #40
0
    protected void btnTest_Click(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();

        foreach (Controls_mfbFileUpload fu in mfbMultiFileUpload1.FileUploadControls)
        {
            if (fu.HasFile)
            {
                sb.AppendFormat(CultureInfo.InvariantCulture, "<hr /><br />File: {0}<br />", fu.PostedFile.FileName);
                System.Drawing.Image image = System.Drawing.Image.FromStream(fu.PostedFile.InputStream, false, false);

                try
                {
                    System.Drawing.Imaging.PropertyItem p = image.GetPropertyItem((int)PropertyTagId.GpsLatitudeRef);
                    sb.Append("Got latitudeRef; ");
                    sb.AppendFormat(CultureInfo.CurrentCulture, "Latitude Ref: {0}<br />", (string)PropertyTag.getValue(p));
                }
                catch (ArgumentException ex)
                {
                    sb.AppendFormat(CultureInfo.CurrentCulture, "Latitude Ref: Not found! {0}<br />", ex.Message);
                }

                try
                {
                    System.Drawing.Imaging.PropertyItem p = image.GetPropertyItem((int)PropertyTagId.GpsLatitude);
                    sb.Append("Got latitude; ");
                    Fraction[] f = (Fraction[])PropertyTag.getValue(p);
                    sb.AppendFormat(CultureInfo.CurrentCulture, "has {0} elements; ", f.Length);
                    sb.AppendFormat(CultureInfo.CurrentCulture, "Latitude values: {0}, {1}, {2}<br />", f[0], f[1], f[2]);
                }
                catch (ArgumentException ex)
                {
                    sb.AppendFormat(CultureInfo.CurrentCulture, "Latitudes values: Not Found! {0}<br />", ex.Message);
                }

                try
                {
                    System.Drawing.Imaging.PropertyItem p = image.GetPropertyItem((int)PropertyTagId.GpsLongitudeRef);
                    sb.Append("Got longitudeRef; ");
                    sb.AppendFormat(CultureInfo.CurrentCulture, "Longitude Ref: {0}<br />", (string)PropertyTag.getValue(p));
                }
                catch (ArgumentException ex)
                {
                    sb.AppendFormat(CultureInfo.CurrentCulture, "Longitude Ref: Not found! {0}<br />", ex.Message);
                }

                try
                {
                    System.Drawing.Imaging.PropertyItem p = image.GetPropertyItem((int)PropertyTagId.GpsLongitude);
                    sb.Append("Got longitude; ");
                    Fraction[] f = (Fraction[])PropertyTag.getValue(p);
                    sb.AppendFormat(CultureInfo.CurrentCulture, "has {0} elements; ", f.Length);
                    sb.AppendFormat(CultureInfo.CurrentCulture, "Longitude values: {0}, {1}, {2}<br />", f[0], f[1], f[2]);
                }
                catch (ArgumentException ex)
                {
                    sb.AppendFormat(CultureInfo.CurrentCulture, "Longitude values: Not Found! {0}<br />", ex.Message);
                }
            }
        }

        lblDiagnose.Text = sb.ToString();
    }
예제 #41
0
        //取得图片的EXIF信息#region 取得图片的EXIF信息 
        public Metadata GetEXIFMetaData(string PhotoName) {
            // 创建一个图片的实例 
            System.Drawing.Image MyImage = System.Drawing.Image.FromFile(PhotoName);
            // 创建一个整型数组来存储图像中属性数组的ID 
            int[] MyPropertyIdList = MyImage.PropertyIdList;
            //创建一个封闭图像属性数组的实例 
            PropertyItem[] MyPropertyItemList = new PropertyItem[MyPropertyIdList.Length];
            //创建一个图像EXIT信息的实例结构对象,并且赋初值 


            
            //创建一个图像EXIT信息的实例结构对象,并且赋初值#region 创建一个图像EXIT信息的实例结构对象,并且赋初值 
            Metadata MyMetadata = new Metadata();
            MyMetadata.EquipmentMake.Hex = "10f";
            MyMetadata.CameraModel.Hex = "110";
            MyMetadata.DatePictureTaken.Hex = "9003";
            MyMetadata.ExposureTime.Hex = "829a";
            MyMetadata.Fstop.Hex = "829d";
            MyMetadata.ShutterSpeed.Hex = "9201";
            MyMetadata.MeteringMode.Hex = "9207";
            MyMetadata.Flash.Hex = "9209";
            MyMetadata.FNumber.Hex = "829d"; //
            MyMetadata.ExposureProg.Hex = ""; //
            MyMetadata.SpectralSense.Hex = "8824"; //
            MyMetadata.ISOSpeed.Hex = "8827"; //
            MyMetadata.OECF.Hex = "8828"; //
            MyMetadata.Ver.Hex = "9000"; //
            MyMetadata.CompConfig.Hex = "9101"; //
            MyMetadata.CompBPP.Hex = "9102"; //
            MyMetadata.Aperture.Hex = "9202"; //
            MyMetadata.Brightness.Hex = "9203"; //
            MyMetadata.ExposureBias.Hex = "9204"; //
            MyMetadata.MaxAperture.Hex = "9205"; //
            MyMetadata.SubjectDist.Hex = "9206"; //
            MyMetadata.LightSource.Hex = "9208"; //
            MyMetadata.FocalLength.Hex = "920a"; //
            MyMetadata.FPXVer.Hex = "a000"; //
            MyMetadata.ColorSpace.Hex = "a001"; //
            MyMetadata.FocalXRes.Hex = "a20e"; //
            MyMetadata.FocalYRes.Hex = "a20f"; //
            MyMetadata.FocalResUnit.Hex = "a210"; //
            MyMetadata.ExposureIndex.Hex = "a215"; //
            MyMetadata.SensingMethod.Hex = "a217"; //
            MyMetadata.SceneType.Hex = "a301";
            MyMetadata.CfaPattern.Hex = "a302";

            // ASCII编码 
            System.Text.ASCIIEncoding Value = new System.Text.ASCIIEncoding();

            int index = 0;
            int MyPropertyIdListCount = MyPropertyIdList.Length;
            if (MyPropertyIdListCount != 0) {
                foreach (int MyPropertyId in MyPropertyIdList) {
                    string hexVal = "";
                    MyPropertyItemList[index] = MyImage.GetPropertyItem(MyPropertyId);

                    //初始化各属性值#region 初始化各属性值 
                    string myPropertyIdString = MyImage.GetPropertyItem(MyPropertyId).Id.ToString("x");
                    switch (myPropertyIdString) {
                        case "10f": {
                                MyMetadata.EquipmentMake.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.EquipmentMake.DisplayValue = Value.GetString(MyPropertyItemList[index].Value);
                                break;
                            }
                        case "110": {
                                MyMetadata.CameraModel.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.CameraModel.DisplayValue = Value.GetString(MyPropertyItemList[index].Value);
                                break;

                            }
                        case "9003": {
                                MyMetadata.DatePictureTaken.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.DatePictureTaken.DisplayValue = Value.GetString(MyPropertyItemList[index].Value);
                                break;
                            }
                        case "9207": {
                                MyMetadata.MeteringMode.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.MeteringMode.DisplayValue = LookupEXIFValue("MeteringMode", BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString());
                                break;
                            }
                        case "9209": {
                                MyMetadata.Flash.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.Flash.DisplayValue = LookupEXIFValue("Flash", BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString());
                                break;
                            }
                        case "829a": {
                                MyMetadata.ExposureTime.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                string StringValue = "";
                                for (int Offset = 0; Offset < MyImage.GetPropertyItem(MyPropertyId).Len; Offset = Offset + 4) {
                                    StringValue += BitConverter.ToInt32(MyImage.GetPropertyItem(MyPropertyId).Value, Offset).ToString() + "/";
                                }
                                MyMetadata.ExposureTime.DisplayValue = StringValue.Substring(0, StringValue.Length - 1);
                                break;
                            }
                        case "829d": {
                                MyMetadata.Fstop.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                int int1;
                                int int2;
                                int1 = BitConverter.ToInt32(MyImage.GetPropertyItem(MyPropertyId).Value, 0);
                                int2 = BitConverter.ToInt32(MyImage.GetPropertyItem(MyPropertyId).Value, 4);
                                MyMetadata.Fstop.DisplayValue = "F/" + (int1 / int2);

                                MyMetadata.FNumber.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.FNumber.DisplayValue = BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString();

                                break;
                            }
                        case "9201": {
                                MyMetadata.ShutterSpeed.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                string StringValue = BitConverter.ToInt32(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString();
                                MyMetadata.ShutterSpeed.DisplayValue = "1/" + StringValue;
                                break;
                            }
                        case "8822": {
                                MyMetadata.ExposureProg.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.ExposureProg.DisplayValue = LookupEXIFValue("ExposureProg", BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString());
                                break;
                            }

                        case "8824": {
                                MyMetadata.SpectralSense.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.SpectralSense.DisplayValue = Value.GetString(MyPropertyItemList[index].Value);
                                break;
                            }
                        case "8827": {
                                hexVal = "";
                                MyMetadata.ISOSpeed.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                hexVal = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value).Substring(0, 2);
                                MyMetadata.ISOSpeed.DisplayValue = Convert.ToInt32(hexVal, 16).ToString();//Value.GetString(MyPropertyItemList[index].Value); 
                                break;
                            }
                        case "8828": {
                                MyMetadata.OECF.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.OECF.DisplayValue = Value.GetString(MyPropertyItemList[index].Value);
                                break;
                            }
                        case "9000": {
                                MyMetadata.Ver.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.Ver.DisplayValue = Value.GetString(MyPropertyItemList[index].Value).Substring(1, 1) + "." + Value.GetString(MyPropertyItemList[index].Value).Substring(2, 2);
                                break;
                            }
                        case "9101": {
                                MyMetadata.CompConfig.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.CompConfig.DisplayValue = LookupEXIFValue("CompConfig", BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString());
                                break;
                            }
                        case "9102": {
                                MyMetadata.CompBPP.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.CompBPP.DisplayValue = BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString();
                                break;
                            }
                        case "9202": {
                                hexVal = "";
                                MyMetadata.Aperture.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                hexVal = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value).Substring(0, 2);
                                hexVal = Convert.ToInt32(hexVal, 16).ToString();
                                hexVal = hexVal + "00";
                                MyMetadata.Aperture.DisplayValue = hexVal.Substring(0, 1) + "." + hexVal.Substring(1, 2);
                                break;
                            }
                        case "9203": {
                                hexVal = "";
                                MyMetadata.Brightness.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                hexVal = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value).Substring(0, 2);
                                hexVal = Convert.ToInt32(hexVal, 16).ToString();
                                hexVal = hexVal + "00";
                                MyMetadata.Brightness.DisplayValue = hexVal.Substring(0, 1) + "." + hexVal.Substring(1, 2);
                                break;
                            }
                        case "9204": {
                                MyMetadata.ExposureBias.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.ExposureBias.DisplayValue = BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString();
                                break;
                            }
                        case "9205": {
                                hexVal = "";
                                MyMetadata.MaxAperture.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                hexVal = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value).Substring(0, 2);
                                hexVal = Convert.ToInt32(hexVal, 16).ToString();
                                hexVal = hexVal + "00";
                                MyMetadata.MaxAperture.DisplayValue = hexVal.Substring(0, 1) + "." + hexVal.Substring(1, 2);
                                break;
                            }
                        case "9206": {
                                MyMetadata.SubjectDist.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.SubjectDist.DisplayValue = Value.GetString(MyPropertyItemList[index].Value);
                                break;
                            }

                        case "9208": {
                                MyMetadata.LightSource.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.LightSource.DisplayValue = LookupEXIFValue("LightSource", BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString());
                                break;
                            }

                        case "920a": {
                                hexVal = "";
                                MyMetadata.FocalLength.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                hexVal = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value).Substring(0, 2);
                                hexVal = Convert.ToInt32(hexVal, 16).ToString();
                                hexVal = hexVal + "00";
                                MyMetadata.FocalLength.DisplayValue = hexVal.Substring(0, 1) + "." + hexVal.Substring(1, 2);
                                break;
                            }
                        case "a000": {
                                MyMetadata.FPXVer.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.FPXVer.DisplayValue = Value.GetString(MyPropertyItemList[index].Value).Substring(1, 1) + "." + Value.GetString(MyPropertyItemList[index].Value).Substring(2, 2);
                                break;
                            }
                        case "a001": {
                                MyMetadata.ColorSpace.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                if (BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString() == "1")
                                    MyMetadata.ColorSpace.DisplayValue = "RGB";
                                if (BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString() == "65535")
                                    MyMetadata.ColorSpace.DisplayValue = "Uncalibrated";
                                break;
                            }
                        case "a20e": {
                                MyMetadata.FocalXRes.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.FocalXRes.DisplayValue = BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString();
                                break;
                            }
                        case "a20f": {
                                MyMetadata.FocalYRes.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.FocalYRes.DisplayValue = BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString();
                                break;
                            }
                        case "a210": {
                                string aa;
                                MyMetadata.FocalResUnit.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                aa = BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString(); ;
                                if (aa == "1") MyMetadata.FocalResUnit.DisplayValue = "没有单位";
                                if (aa == "2") MyMetadata.FocalResUnit.DisplayValue = "英尺";
                                if (aa == "3") MyMetadata.FocalResUnit.DisplayValue = "厘米";
                                break;
                            }
                        case "a215": {
                                MyMetadata.ExposureIndex.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.ExposureIndex.DisplayValue = Value.GetString(MyPropertyItemList[index].Value);
                                break;
                            }
                        case "a217": {
                                string aa;
                                aa = BitConverter.ToInt16(MyImage.GetPropertyItem(MyPropertyId).Value, 0).ToString();
                                MyMetadata.SensingMethod.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                if (aa == "2") MyMetadata.SensingMethod.DisplayValue = "1 chip color area sensor";
                                break;
                            }
                        case "a301": {
                                MyMetadata.SceneType.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.SceneType.DisplayValue = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                break;
                            }
                        case "a302": {
                                MyMetadata.CfaPattern.RawValueAsString = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                MyMetadata.CfaPattern.DisplayValue = BitConverter.ToString(MyImage.GetPropertyItem(MyPropertyId).Value);
                                break;
                            }
                    }
                    index++;
                }
            }

            MyMetadata.XResolution.DisplayValue = MyImage.HorizontalResolution.ToString();
            MyMetadata.YResolution.DisplayValue = MyImage.VerticalResolution.ToString();
            MyMetadata.ImageHeight.DisplayValue = MyImage.Height.ToString();
            MyMetadata.ImageWidth.DisplayValue = MyImage.Width.ToString();
            MyImage.Dispose();
            return MyMetadata;
        }
예제 #42
0
        ///<summary>Transformes value of the PropertyItem.Value byte array to apropriate .NET Framework type.</summary>
        /// <param name="aPropertyItem"></param>
        public static Object getValue(PropertyItem aPropertyItem)
        {
            if (aPropertyItem==null) return null;
                switch ((PropertyTagType)aPropertyItem.Type) {

                    case PropertyTagType.Byte:
                        if (aPropertyItem.Value.Length == 1)  return aPropertyItem.Value[0];
                        return aPropertyItem.Value;

                    case PropertyTagType.ASCII:
                        return _encoding.GetString( aPropertyItem.Value, 0, aPropertyItem.Len - 1);

                    case PropertyTagType.Short:
                            ushort[] _resultUShort = new ushort[aPropertyItem.Len / (16 / 8) ];
                            for (int i=0; i<_resultUShort.Length ; i++)
                                _resultUShort[i]=BitConverter.ToUInt16(aPropertyItem.Value,i*(16 / 8));
                            if (_resultUShort.Length==1) return _resultUShort[0];
                            return (_resultUShort);

                    case PropertyTagType.Long :
                            uint [] _resultUInt32 = new uint[aPropertyItem.Len / (32 / 8)];
                            for (int i=0; i<_resultUInt32.Length; i++)
                                _resultUInt32[i]=	BitConverter.ToUInt32(aPropertyItem.Value, i*(32 / 8));
                            if (_resultUInt32.Length==1) return _resultUInt32[0];
                            return _resultUInt32;

                    case PropertyTagType.Rational :
                            Fraction[] _resultRational = new Fraction[aPropertyItem.Len / (64 / 8)];
                            uint uNominator;
                            uint uDenominator;
                            for (int i=0; i<_resultRational.Length; i++)
                            {
                                uNominator=1;
                                uNominator 	 = BitConverter.ToUInt32(aPropertyItem.Value, i*(64 / 8)  );
                                uDenominator  = BitConverter.ToUInt32(aPropertyItem.Value, (i*(64 / 8)) + (32/8));
                                _resultRational[i]= new Fraction(uNominator, uDenominator);
                                if (_resultRational[i]==null) MessageBox.Show("Null");
                            }
                            if (_resultRational.Length==1) return _resultRational[0];
                            return _resultRational;

                    case PropertyTagType.Undefined:
                            if (aPropertyItem.Value.Length == 1)  return aPropertyItem.Value[0];
                            return aPropertyItem.Value;

                    case PropertyTagType.SLONG:
                            int [] _resultInt32 = new int[aPropertyItem.Len / (32 / 8)];
                            for (int i=0; i<_resultInt32.Length; i++)
                                _resultInt32[i]=	BitConverter.ToInt32(aPropertyItem.Value, i*(32/8));
                            if (_resultInt32.Length==1) return _resultInt32[0];
                            return _resultInt32;

                    case PropertyTagType.SRational:
                            Fraction[] _resultSRational = new Fraction[aPropertyItem.Len / (64 / 8)];
                            int sNominator;
                            int sDenominator;
                            for (int i=0; i<_resultSRational.Length; i++)
                            {
                                sNominator 	 = BitConverter.ToInt32(aPropertyItem.Value, i*(64/8));
                                sDenominator  = BitConverter.ToInt32(aPropertyItem.Value, i*(64/8)+(32/8));
                                _resultSRational[i]= new Fraction(sNominator, sDenominator);
                            }
                            if (_resultSRational.Length==1) return _resultSRational[0];
                            return _resultSRational;

                    default:
                        if (aPropertyItem.Value.Length == 1)  return aPropertyItem.Value[0];
                        return aPropertyItem.Value;
            }
        }
예제 #43
0
 ///<summary></summary>
 /// <param name="aPropertyItem"></param>
 public PropertyTag(PropertyItem aPropertyItem)
 {
     _prop=aPropertyItem;
 }
예제 #44
0
 public static PropertyItem2 FromPropertyItem(PropertyItem pi)
 {
     return new PropertyItem2(pi.Id, pi.Len, pi.Type, pi.Value);
 }
예제 #45
0
 internal bool <LoadProperties> b__5_0(System.Drawing.Imaging.PropertyItem _) =>
 true;
예제 #46
0
        private static ImageProperty[] GetAllPropertiesInternal(IImageDecoder decoder)
        {
            uint num;
            uint num2;
            if (decoder == null)
            {
                throw new ArgumentNullException();
            }
            List<ImageProperty> list = new List<ImageProperty>(ImageUtils.GetAllTags(decoder).Length);
            decoder.GetPropertySize(out num, out num2);

            // Если драйвер возвращает заведомо мало информации, то значит она битая и вытащить
            // оттуда всё равно ничего не вытащить. Число 30 взято исходя из опытных расчётов.
            // Выходим из процедуры, иначе вывалится ошибка COM.
            if (num < num2 * 30)
                return list.ToArray();

            IntPtr pItems = Marshal.AllocHGlobal((int)num);
            PropertyItem[] itemArray = new PropertyItem[num2];
            decoder.GetAllPropertyItems(num, num2, pItems);
            IntPtr ptr = pItems;
            for (uint i = 0; i < num2; i++)
            {
                itemArray[i] = (PropertyItem)Marshal.PtrToStructure(ptr, typeof(PropertyItem));
                ptr = (IntPtr)(ptr.ToInt32() + Marshal.SizeOf(typeof(PropertyItem)));
            }
            foreach (PropertyItem item in itemArray)
            {
                list.Add(ImageUtils.LoadProperty(item));
            }
            Marshal.FreeHGlobal(pItems);
            return list.ToArray();
        }