public static extern bool ImageList_GetImageInfo(HandleRef himl, int i, System.Windows.Forms.NativeMethods.IMAGEINFO pImageInfo);
        private Bitmap GetBitmap(int index)
        {
            if ((index < 0) || (index >= this.Images.Count))
            {
                throw new ArgumentOutOfRangeException("index", System.Windows.Forms.SR.GetString("InvalidArgument", new object[] { "index", index.ToString(CultureInfo.CurrentCulture) }));
            }
            Bitmap image = null;

            if (this.ColorDepth == System.Windows.Forms.ColorDepth.Depth32Bit)
            {
                System.Windows.Forms.NativeMethods.IMAGEINFO pImageInfo = new System.Windows.Forms.NativeMethods.IMAGEINFO();
                if (System.Windows.Forms.SafeNativeMethods.ImageList_GetImageInfo(new HandleRef(this, this.Handle), index, pImageInfo))
                {
                    Bitmap     bitmap2    = null;
                    BitmapData bmpData    = null;
                    BitmapData targetData = null;
                    System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
                    try
                    {
                        bitmap2 = Image.FromHbitmap(pImageInfo.hbmImage);
                        bmpData = bitmap2.LockBits(new Rectangle(pImageInfo.rcImage_left, pImageInfo.rcImage_top, pImageInfo.rcImage_right - pImageInfo.rcImage_left, pImageInfo.rcImage_bottom - pImageInfo.rcImage_top), ImageLockMode.ReadOnly, bitmap2.PixelFormat);
                        int stride = bmpData.Stride;
                        int height = this.imageSize.Height;
                        if (BitmapHasAlpha(bmpData))
                        {
                            image      = new Bitmap(this.imageSize.Width, this.imageSize.Height, PixelFormat.Format32bppArgb);
                            targetData = image.LockBits(new Rectangle(0, 0, this.imageSize.Width, this.imageSize.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                            this.CopyBitmapData(bmpData, targetData);
                        }
                    }
                    finally
                    {
                        CodeAccessPermission.RevertAssert();
                        if (bitmap2 != null)
                        {
                            if (bmpData != null)
                            {
                                bitmap2.UnlockBits(bmpData);
                            }
                            bitmap2.Dispose();
                        }
                        if ((image != null) && (targetData != null))
                        {
                            image.UnlockBits(targetData);
                        }
                    }
                }
            }
            if (image == null)
            {
                image = new Bitmap(this.imageSize.Width, this.imageSize.Height);
                using (Graphics graphics = Graphics.FromImage(image))
                {
                    IntPtr hdc = graphics.GetHdc();
                    try
                    {
                        System.Windows.Forms.SafeNativeMethods.ImageList_DrawEx(new HandleRef(this, this.Handle), index, new HandleRef(graphics, hdc), 0, 0, this.imageSize.Width, this.imageSize.Height, -1, -1, 1);
                    }
                    finally
                    {
                        graphics.ReleaseHdcInternal(hdc);
                    }
                }
            }
            image.MakeTransparent(fakeTransparencyColor);
            return(image);
        }
 private Bitmap GetBitmap(int index)
 {
     if ((index < 0) || (index >= this.Images.Count))
     {
         throw new ArgumentOutOfRangeException("index", System.Windows.Forms.SR.GetString("InvalidArgument", new object[] { "index", index.ToString(CultureInfo.CurrentCulture) }));
     }
     Bitmap image = null;
     if (this.ColorDepth == System.Windows.Forms.ColorDepth.Depth32Bit)
     {
         System.Windows.Forms.NativeMethods.IMAGEINFO pImageInfo = new System.Windows.Forms.NativeMethods.IMAGEINFO();
         if (System.Windows.Forms.SafeNativeMethods.ImageList_GetImageInfo(new HandleRef(this, this.Handle), index, pImageInfo))
         {
             Bitmap bitmap2 = null;
             BitmapData bmpData = null;
             BitmapData targetData = null;
             System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
             try
             {
                 bitmap2 = Image.FromHbitmap(pImageInfo.hbmImage);
                 bmpData = bitmap2.LockBits(new Rectangle(pImageInfo.rcImage_left, pImageInfo.rcImage_top, pImageInfo.rcImage_right - pImageInfo.rcImage_left, pImageInfo.rcImage_bottom - pImageInfo.rcImage_top), ImageLockMode.ReadOnly, bitmap2.PixelFormat);
                 int stride = bmpData.Stride;
                 int height = this.imageSize.Height;
                 if (BitmapHasAlpha(bmpData))
                 {
                     image = new Bitmap(this.imageSize.Width, this.imageSize.Height, PixelFormat.Format32bppArgb);
                     targetData = image.LockBits(new Rectangle(0, 0, this.imageSize.Width, this.imageSize.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                     this.CopyBitmapData(bmpData, targetData);
                 }
             }
             finally
             {
                 CodeAccessPermission.RevertAssert();
                 if (bitmap2 != null)
                 {
                     if (bmpData != null)
                     {
                         bitmap2.UnlockBits(bmpData);
                     }
                     bitmap2.Dispose();
                 }
                 if ((image != null) && (targetData != null))
                 {
                     image.UnlockBits(targetData);
                 }
             }
         }
     }
     if (image == null)
     {
         image = new Bitmap(this.imageSize.Width, this.imageSize.Height);
         using (Graphics graphics = Graphics.FromImage(image))
         {
             IntPtr hdc = graphics.GetHdc();
             try
             {
                 System.Windows.Forms.SafeNativeMethods.ImageList_DrawEx(new HandleRef(this, this.Handle), index, new HandleRef(graphics, hdc), 0, 0, this.imageSize.Width, this.imageSize.Height, -1, -1, 1);
             }
             finally
             {
                 graphics.ReleaseHdcInternal(hdc);
             }
         }
     }
     image.MakeTransparent(fakeTransparencyColor);
     return image;
 }