private void ReadImageProperties()
            {
                this.HasCapabilities &= ImagePropertyProvider.TagCapability.Thumbnail;
                this.FrameCount = -1;
                this.BPP = -1;
                try
                {
                    PropertyItem[] propertyItems = null;
                    using (Stream stream = this._FileInfo.OpenRead())
                    {
                        using (Image image = Image.FromStream(stream, false, false))
                        {
                            propertyItems = image.PropertyItems;
                            this.ImageSize = image.Size;
                            this.HasCapabilities |= ImagePropertyProvider.TagCapability.Size;
                            this.BPP = Image.GetPixelFormatSize(image.PixelFormat);
                            this.HasCapabilities |= ImagePropertyProvider.TagCapability.BPP;
                            switch (image.PixelFormat)
                            {
                                case PixelFormat.Format16bppRgb555:
                                case PixelFormat.Format16bppRgb565:
                                case PixelFormat.Format24bppRgb:
                                case PixelFormat.Format32bppRgb:
                                case PixelFormat.Format16bppArgb1555:
                                case PixelFormat.Format32bppPArgb:
                                case PixelFormat.Format32bppArgb:
                                case PixelFormat.Format64bppArgb:
                                case PixelFormat.Format48bppRgb:
                                case PixelFormat.Format64bppPArgb:
                                    this.Space = ColorSpace.RGB;
                                    break;

                                case PixelFormat.Indexed:
                                case PixelFormat.Format4bppIndexed:
                                case PixelFormat.Format8bppIndexed:
                                case PixelFormat.Format1bppIndexed:
                                    this.Space = ColorSpace.Indexed;
                                    break;

                                case PixelFormat.Format16bppGrayScale:
                                    this.Space = ColorSpace.Grayscale;
                                    break;
                            }
                            if ((image.Flags & 0x10) > 0)
                            {
                                this.Space = ColorSpace.RGB;
                            }
                            else if ((image.Flags & 0x20) > 0)
                            {
                                this.Space = ColorSpace.CMYK;
                            }
                            else if ((image.Flags & 0x40) > 0)
                            {
                                this.Space = ColorSpace.Grayscale;
                            }
                            else if ((image.Flags & 0x80) > 0)
                            {
                                this.Space = ColorSpace.YCBCR;
                            }
                            else if ((image.Flags & 0x100) > 0)
                            {
                                this.Space = ColorSpace.YCCK;
                            }
                            if (image.RawFormat == ImageFormat.Gif)
                            {
                                this.Space = ColorSpace.Indexed;
                            }
                            this.HasCapabilities |= ImagePropertyProvider.TagCapability.ColorSpace;
                            if ((image.Flags & 0x1000) > 0)
                            {
                                this.DPI = new Size((int) image.HorizontalResolution, (int) image.VerticalResolution);
                                this.HasCapabilities |= ImagePropertyProvider.TagCapability.DPI;
                            }
                            foreach (Guid guid in image.FrameDimensionsList)
                            {
                                if (guid == FrameDimension.Page.Guid)
                                {
                                    this.FrameCount = image.GetFrameCount(FrameDimension.Page);
                                }
                                else if (guid == FrameDimension.Resolution.Guid)
                                {
                                    this.FrameCount = image.GetFrameCount(FrameDimension.Resolution);
                                }
                                else if (guid == FrameDimension.Time.Guid)
                                {
                                    this.FrameCount = image.GetFrameCount(FrameDimension.Time);
                                }
                                if (this.FrameCount > 1)
                                {
                                    goto Label_036D;
                                }
                            }
                        }
                    }
                Label_036D:
                    if (this.FrameCount > 0)
                    {
                        this.HasCapabilities |= ImagePropertyProvider.TagCapability.Frames;
                    }
                    if (propertyItems.Length > 0)
                    {
                        this.ImagePropertyList = new Dictionary<int, object>();
                        foreach (PropertyItem item in propertyItems)
                        {
                            int num;
                            if (ImagePropertyProvider.PropertyTagMap.TryGetValue((PropertyTag) item.Id, out num))
                            {
                                this.ImagePropertyList.Add(num, item);
                                this.HasCapabilities |= ImagePropertyProvider.TagCapability.Properties;
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    PropertyProviderManager.ProviderTrace.TraceException(TraceEventType.Error, exception);
                }
            }
 private Image ReadImageThumbnail(ref Size maxThumbnailSize)
 {
     Image target = null;
     Stream stream = null;
     Image image = null;
     if ((this.StoredThumbnail != null) && this.StoredThumbnail.IsAlive)
     {
         target = (Image) this.StoredThumbnail.Target;
     }
     if ((target == null) || (this.StoredThumbnailSize != maxThumbnailSize))
     {
         try
         {
             stream = this._FileInfo.OpenRead();
             image = Image.FromStream(stream, true);
             if (((image.Width <= maxThumbnailSize.Width) && (image.Height <= maxThumbnailSize.Height)) && ImageAnimator.CanAnimate(image))
             {
                 this.StoredThumbnailStream = new WeakReference(stream);
                 target = image;
             }
             else
             {
                 try
                 {
                     using (MemoryStream stream2 = new MemoryStream(image.GetPropertyItem(0x501b).Value))
                     {
                         using (Image image3 = Image.FromStream(stream2))
                         {
                             if (ImagePropertyProvider.KeepThumbnailSize || ((image3.Width <= maxThumbnailSize.Width) && (image3.Height <= maxThumbnailSize.Height)))
                             {
                                 target = new Bitmap(image3);
                             }
                             else
                             {
                                 target = new Bitmap(image3, ImageHelper.GetThumbnailSize(image3.Size, maxThumbnailSize));
                             }
                         }
                     }
                 }
                 catch
                 {
                 }
                 if (target == null)
                 {
                     if ((image.Width <= maxThumbnailSize.Width) && (image.Height <= maxThumbnailSize.Height))
                     {
                         target = new Bitmap(image);
                     }
                     else
                     {
                         target = new Bitmap(image, ImageHelper.GetThumbnailSize(image.Size, maxThumbnailSize));
                     }
                 }
             }
             RotateFlipType rotateFlipType = (RotateFlipType) Convert.ToInt32(PropertyTagHelper.GetPropertyValue(image, PropertyTag.Orientation));
             if (rotateFlipType != RotateFlipType.RotateNoneFlipNone)
             {
                 target.RotateFlip(rotateFlipType);
             }
             this.StoredThumbnail = new WeakReference(target);
             this.StoredThumbnailSize = maxThumbnailSize;
         }
         catch (Exception exception)
         {
             PropertyProviderManager.ProviderTrace.TraceException(TraceEventType.Error, exception);
             this.HasCapabilities &= ~ImagePropertyProvider.TagCapability.Thumbnail;
             base.ResetAvailableSet();
         }
         finally
         {
             if ((stream != null) && (image != target))
             {
                 stream.Dispose();
             }
             if ((image != null) && (image != target))
             {
                 image.Dispose();
             }
         }
     }
     return target;
 }
 public ImagePropertyBag(FileInfo fileInfo, ImagePropertyProvider.TagCapability capabilities)
 {
     this._FileInfo = fileInfo;
     this.HasCapabilities = capabilities | ~(ImagePropertyProvider.TagCapability.Exif | ImagePropertyProvider.TagCapability.Properties | ImagePropertyProvider.TagCapability.Frames);
 }