ImageList.cs: Add(Icon): Use Graphics.DrawIcon instead of Icon.ToBitmap.
authorKornél Pál <kornelpal@gmail.com>
Fri, 30 Sep 2005 12:22:58 +0000 (12:22 -0000)
committerKornél Pál <kornelpal@gmail.com>
Fri, 30 Sep 2005 12:22:58 +0000 (12:22 -0000)
svn path=/trunk/mcs/; revision=51039

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ImageList.cs

index d7eae3d0f17bbf3be973803b1fc8e23221b47868..19c329eabce89e7ac2ba6b0597aadf5e85552ba5 100644 (file)
@@ -1,3 +1,7 @@
+2005-09-30  Kornél Pál  <kornelpal@hotmail.com>
+
+       * ImageList.cs: Add(Icon): Use Graphics.DrawIcon instead of Icon.ToBitmap.
+
 2005-09-30  Kornél Pál  <kornelpal@hotmail.com>
 
        * ImageList.cs: ReduceColorDepth: Clean up pointer operations.
index 9f990ed22392f0a9d2e48f6f95509afdaa289ae3..6ef121794a56ce11711ae80b05b5bd6426940257 100644 (file)
@@ -347,7 +347,7 @@ namespace System.Windows.Forms
                                        imageAttributes.SetColorKey(transparentColor, transparentColor);
                                }
 
-                               bitmap = new Bitmap((width = this.imageSize.Width), (height = this.imageSize.Height), PixelFormat.Format32bppArgb);
+                               bitmap = new Bitmap(width = this.imageSize.Width, height = this.imageSize.Height, PixelFormat.Format32bppArgb);
                                graphics = Graphics.FromImage(bitmap);
                                graphics.DrawImage(value, new Rectangle(0, 0, width, height), 0, 0, value.Width, value.Height, GraphicsUnit.Pixel, imageAttributes);
                                graphics.Dispose();
@@ -383,12 +383,12 @@ namespace System.Windows.Forms
                                                stride = bitmapData.Stride;
 
                                                if (this.colorDepth < ColorDepth.Depth16Bit) {
-                                                       palette = (this.colorDepth < ColorDepth.Depth8Bit) ? IndexedColorDepths.Palette4Bit : IndexedColorDepths.Palette8Bit;
+                                                       palette = this.colorDepth < ColorDepth.Depth8Bit ? IndexedColorDepths.Palette4Bit : IndexedColorDepths.Palette8Bit;
 
                                                        for (line = 0; line < height; line++) {
                                                                lineEndPtr = linePtr + widthBytes;
                                                                for (pixelPtr = linePtr; pixelPtr < lineEndPtr; pixelPtr += 4)
-                                                                       *(int*)pixelPtr = (((pixel = *(int*)pixelPtr) & AlphaMask) == 0) ? 0x00000000 : IndexedColorDepths.GetNearestColor(palette, pixel | AlphaMask);
+                                                                       *(int*)pixelPtr = ((pixel = *(int*)pixelPtr) & AlphaMask) == 0 ? 0x00000000 : IndexedColorDepths.GetNearestColor(palette, pixel | AlphaMask);
                                                                linePtr += stride;
                                                        }
                                                }
@@ -396,7 +396,7 @@ namespace System.Windows.Forms
                                                        for (line = 0; line < height; line++) {
                                                                lineEndPtr = linePtr + widthBytes;
                                                                for (pixelPtr = linePtr; pixelPtr < lineEndPtr; pixelPtr += 4)
-                                                                       *(int*)pixelPtr = (((pixel = *(int*)pixelPtr) & AlphaMask) == 0) ? 0x00000000 : (pixel & 0x00F8F8F8) | AlphaMask;
+                                                                       *(int*)pixelPtr = ((pixel = *(int*)pixelPtr) & AlphaMask) == 0 ? 0x00000000 : (pixel & 0x00F8F8F8) | AlphaMask;
                                                                linePtr += stride;
                                                        }
                                                }
@@ -404,7 +404,7 @@ namespace System.Windows.Forms
                                                        for (line = 0; line < height; line++) {
                                                                lineEndPtr = linePtr + widthBytes;
                                                                for (pixelPtr = linePtr; pixelPtr < lineEndPtr; pixelPtr += 4)
-                                                                       *(int*)pixelPtr = (((pixel = *(int*)pixelPtr) & AlphaMask) == 0) ? 0x00000000 : pixel | AlphaMask;
+                                                                       *(int*)pixelPtr = ((pixel = *(int*)pixelPtr) & AlphaMask) == 0 ? 0x00000000 : pixel | AlphaMask;
                                                                linePtr += stride;
                                                        }
                                                }
@@ -441,14 +441,20 @@ namespace System.Windows.Forms
                        #region ImageCollection Public Instance Methods
                        public void Add(Icon value)
                        {
+                               int width;
+                               int height;
                                Bitmap bitmap;
+                               Graphics graphics;
 
                                if (value == null)
                                        throw new ArgumentNullException("value");
 
-                               bitmap = value.ToBitmap();
-                               Add(bitmap, Color.Transparent);
-                               bitmap.Dispose();
+                               bitmap = new Bitmap(width = this.imageSize.Width, height = this.imageSize.Height, PixelFormat.Format32bppArgb);
+                               graphics = Graphics.FromImage(bitmap);
+                               graphics.DrawIcon(value, new Rectangle(0, 0, width, height));
+                               graphics.Dispose();
+
+                               list.Add(ReduceColorDepth(bitmap));
                        }
 
                        public void Add(Image value)
@@ -598,12 +604,12 @@ namespace System.Windows.Forms
 
                        bool IList.Contains(object value)
                        {
-                               return (value is Image) ? this.Contains((Image)value) : false;
+                               return value is Image ? this.Contains((Image)value) : false;
                        }
 
                        int IList.IndexOf(object value)
                        {
-                               return (value is Image) ? this.IndexOf((Image)value) : -1;
+                               return value is Image ? this.IndexOf((Image)value) : -1;
                        }
 
                        void IList.Insert(int index, object value)