private Bitmap Extract(int width, int height, IEIFLAG flags, bool scale, bool aspect)
        {
            IntPtr zero = IntPtr.Zero;
            SIZE   sIZE = default(SIZE);

            sIZE.cx = width;
            sIZE.cy = height;
            PixelFormat   bgra = PixelFormats.Bgra32;
            BitmapPalette halftone256Transparent = BitmapPalettes.Halftone256Transparent;
            int           num = (width * bgra.BitsPerPixel + 7) / 8;

            byte[]       pixels = new byte[num * height];
            BitmapSource bmpSrc = BitmapSource.Create(width, height, 96.0, 96.0, bgra, halftone256Transparent, pixels, num);

            try
            {
                if (this._extractImage != null)
                {
                    StringBuilder stringBuilder = new StringBuilder(260);
                    int           num2          = 0;
                    this.hResult = this._extractImage.GetLocation(stringBuilder, stringBuilder.Capacity, ref num2, ref sIZE, 32, ref flags);
                    if (this.hResult != 0)
                    {
                        Marshal.ThrowExceptionForHR(this.hResult);
                    }
                    this.hResult = this._extractImage.Extract(out zero);
                    if (this.hResult != 0)
                    {
                        Marshal.ThrowExceptionForHR(this.hResult);
                    }
                    BitmapSource bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(zero, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    if (scale && (bitmapSource.PixelHeight != sIZE.cy || bitmapSource.PixelWidth != sIZE.cx))
                    {
                        return(this.BmpFromBmpSource(ShellMgr.ScaleImage(bitmapSource, sIZE.cx, sIZE.cy, aspect)));
                    }
                    return(this.BmpFromBmpSource(bitmapSource));
                }
                return(this.BmpFromBmpSource(bmpSrc));
            }
            catch (COMException)
            {
                return(this.BmpFromBmpSource(bmpSrc));
            }
            catch (Exception)
            {
                return(this.BmpFromBmpSource(bmpSrc));
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    Marshal.Release(zero);
                }
            }
        }
 private void GenerateIExtractImage()
 {
     try
     {
         ShellMgr.SHGetDesktopFolder(out this._desktopFolder);
         int num  = 0;
         int num2 = 0;
         this.hResult = this._desktopFolder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, System.IO.Path.GetDirectoryName(this._path), out num2, out this._folderPidl, out num);
         if (this.hResult != 0)
         {
             Marshal.ThrowExceptionForHR(this.hResult);
         }
         this.hResult = this._desktopFolder.BindToObject(this._folderPidl, IntPtr.Zero, ref this.iidShellFolder, ref this._folder);
         if (this.hResult != 0)
         {
             Marshal.ThrowExceptionForHR(this.hResult);
         }
         this.hResult = this._folder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, System.IO.Path.GetFileName(this._path), out num2, out this._filePidl, out num);
         if (this.hResult != 0)
         {
             Marshal.ThrowExceptionForHR(this.hResult);
         }
         IUnknown unknown = null;
         this.hResult = this._folder.GetUIObjectOf(IntPtr.Zero, 1, ref this._filePidl, ref this.iidExtractImage, out this._reserved, ref unknown);
         if (this.hResult != 0)
         {
             Marshal.ThrowExceptionForHR(this.hResult);
         }
         this._extractImage = (IExtractImage)unknown;
     }
     catch (FileNotFoundException)
     {
     }
     catch (COMException)
     {
     }
     catch (Exception)
     {
     }
 }