public static ImageProperty[] GetAllProperties(IImageDecoder decoder) { if (decoder == null) { throw new ArgumentNullException(); } ImageTag[] propTags = GetAllTags(decoder); List <ImageProperty> allProps = new List <ImageProperty>(propTags.Length); uint cbAllProps; uint numProps; decoder.GetPropertySize(out cbAllProps, out numProps); IntPtr pProps = Marshal.AllocHGlobal((int)cbAllProps); PropertyItem[] allItems = new PropertyItem[numProps]; decoder.GetAllPropertyItems(cbAllProps, numProps, pProps); IntPtr pProp = pProps; for (uint i = 0; i < numProps; i++) { allItems[i] = (PropertyItem)Marshal.PtrToStructure(pProp, typeof(PropertyItem)); pProp = (IntPtr)(pProp.ToInt32() + Marshal.SizeOf(typeof(PropertyItem))); } foreach (PropertyItem pi in allItems) { allProps.Add(LoadProperty(pi)); } Marshal.FreeHGlobal(pProps); return(allProps.ToArray()); }
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()); }
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(); }