ClearColorKey() public method

public ClearColorKey ( ) : void
return void
 /// <summary>
 /// Creates the disabled image for the specified Image
 /// </summary>
 /// <param name="normalImage"></param>
 /// <returns></returns>
 public static Image CreateDisabledImage(Image normalImage)
 {
     var imageAttr = new ImageAttributes();
     imageAttr.ClearColorKey();
     imageAttr.SetColorMatrix(DisabledImageColorMatrix);
     var size = normalImage.Size;
     var image = new Bitmap(size.Width, size.Height);
     var graphics = Graphics.FromImage(image);
     graphics.DrawImage(normalImage, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, imageAttr);
     graphics.Dispose();
     return image;
 }
		/*
		 * GetDesaturatedImageAttributes
		 */

		/// <summary>
		/// </summary>
		/// <returns></returns>
		public static ImageAttributes GetDesaturatedImageAttributes()
		{
			float[][] matrixComponents = new float[5][];
			matrixComponents[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f };
			matrixComponents[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f };
			matrixComponents[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f };
			
			float[] transformComponents = new float[5];
			transformComponents[3] = 1f;
			matrixComponents[3] = transformComponents;
			matrixComponents[4] = new float[] { 0.38f, 0.38f, 0.38f, 0f, 1f };
			
			ImageAttributes imageAttributes = new ImageAttributes();
			imageAttributes.ClearColorKey();
			imageAttributes.SetColorMatrix(new ColorMatrix(matrixComponents));

			return imageAttributes;
		}
Example #3
0
        public static Image GetDisabledImage(Image originalBitmap)
        {
            var disabledBitmap = new Bitmap(originalBitmap.Width, originalBitmap.Height);
            var g = Graphics.FromImage(disabledBitmap);

            // We create a color matrix to generated the disabled look
            var array = new float[5][];
            array[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0, 0 };
            array[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0, 0 };
            array[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0, 0 };
            array[3] = new float[] { 0, 0, 0, 1, 0 };
            array[4] = new float[] { 0.38f, 0.38f, 0.38f, 0, 1 };
            var grayMatrix = new ColorMatrix(array);
            var disabledImageAttr = new ImageAttributes();
            disabledImageAttr.ClearColorKey();
            disabledImageAttr.SetColorMatrix(grayMatrix);

            // We draw the image using the color matrix
            var rectImage = new Rectangle(0, 0, originalBitmap.Width, originalBitmap.Height);
            g.DrawImage(originalBitmap, rectImage, 0, 0, originalBitmap.Width, originalBitmap.Height, GraphicsUnit.Pixel, disabledImageAttr);
            g.Dispose();

            return disabledBitmap;
        }
 internal static void DrawImageDisabled(Graphics graphics, Image image, Rectangle imageBounds, Color background, bool unscaledImage)
 {
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     if (image == null)
     {
         throw new ArgumentNullException("image");
     }
     Size size = image.Size;
     if (disabledImageAttr == null)
     {
         float[][] newColorMatrix = new float[5][];
         newColorMatrix[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f };
         newColorMatrix[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f };
         newColorMatrix[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f };
         float[] numArray2 = new float[5];
         numArray2[3] = 1f;
         newColorMatrix[3] = numArray2;
         newColorMatrix[4] = new float[] { 0.38f, 0.38f, 0.38f, 0f, 1f };
         ColorMatrix matrix = new ColorMatrix(newColorMatrix);
         disabledImageAttr = new ImageAttributes();
         disabledImageAttr.ClearColorKey();
         disabledImageAttr.SetColorMatrix(matrix);
     }
     if (unscaledImage)
     {
         using (Bitmap bitmap = new Bitmap(image.Width, image.Height))
         {
             using (Graphics graphics2 = Graphics.FromImage(bitmap))
             {
                 graphics2.DrawImage(image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, disabledImageAttr);
             }
             graphics.DrawImageUnscaled(bitmap, imageBounds);
             return;
         }
     }
     graphics.DrawImage(image, imageBounds, 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, disabledImageAttr);
 }
Example #5
0
       /// <include file='doc\ToolStripRenderer.uex' path='docs/doc[@for="ToolStripRenderer.CreateDisabledImage"]/*' />
       public static Image CreateDisabledImage(Image normalImage) {
           ImageAttributes imgAttrib = new ImageAttributes();
           imgAttrib.ClearColorKey();
           imgAttrib.SetColorMatrix(DisabledImageColorMatrix);
 
           Size size = normalImage.Size;
           Bitmap disabledBitmap = new Bitmap(size.Width, size.Height);
           Graphics graphics = Graphics.FromImage(disabledBitmap);
 
           graphics.DrawImage(normalImage, 
                              new Rectangle(0, 0, size.Width, size.Height), 
                              0, 0, size.Width, size.Height,
                              GraphicsUnit.Pixel, 
                              imgAttrib);
           graphics.Dispose();
 
           return disabledBitmap;
       }
 private void DrawAlphaImage(Image alphaImage, Image image, float percent)
 {
     float[][] newColorMatrix = new float[5][];
     newColorMatrix[0] = new float[] { 1, 0, 0, 0, 0 };
     newColorMatrix[1] = new float[] { 0, 1, 0, 0, 0 };
     newColorMatrix[2] = new float[] { 0, 0, 1, 0, 0 };
     newColorMatrix[3] = new float[] { 0, 0, 0, percent, 0 };
     newColorMatrix[4] = new float[] { 0, 0, 0, 0, 1 };
     ColorMatrix matrix = new ColorMatrix(newColorMatrix);
     ImageAttributes imageAttributes = new ImageAttributes();
     imageAttributes.ClearColorKey();
     imageAttributes.SetColorMatrix(matrix);
     using (Graphics gr = Graphics.FromImage(alphaImage))
     {
         gr.DrawImage(image, new Rectangle(0, 0, Size.Width, Size.Height), 0, 0, Size.Width, Size.Height, GraphicsUnit.Pixel, imageAttributes);
     }
 }
Example #7
0
 private void DrawForegroundFromButton(PaintEventArgs pevent)
 {
     if (_imageButton == null)
     {
         _imageButton = new Button();
         _imageButton.Parent = new TransparentControl();
         _imageButton.SuspendLayout();
         _imageButton.BackColor = Color.Transparent;
         _imageButton.FlatAppearance.BorderSize = 0;
         _imageButton.FlatStyle = FlatStyle.Flat;
     }
     else
     {
         _imageButton.SuspendLayout();
     }
     _imageButton.AutoEllipsis = AutoEllipsis;
     if (Enabled)
     {
         _imageButton.ForeColor = ForeColor;
     }
     else
     {
         _imageButton.ForeColor = Color.FromArgb((3*ForeColor.R + _backColor.R) >> 2,
                                                 (3*ForeColor.G + _backColor.G) >> 2,
                                                 (3*ForeColor.B + _backColor.B) >> 2);
     }
     _imageButton.Font = Font;
     _imageButton.RightToLeft = RightToLeft;
     _imageButton.Image = Image;
     if (Image != null && !Enabled)
     {
         Size size = Image.Size;
         var newColorMatrix = new float[5][];
         newColorMatrix[0] = new[] {0.2125f, 0.2125f, 0.2125f, 0f, 0f};
         newColorMatrix[1] = new[] {0.2577f, 0.2577f, 0.2577f, 0f, 0f};
         newColorMatrix[2] = new[] {0.0361f, 0.0361f, 0.0361f, 0f, 0f};
         var arr = new float[5];
         arr[3] = 1f;
         newColorMatrix[3] = arr;
         newColorMatrix[4] = new[] {0.38f, 0.38f, 0.38f, 0f, 1f};
         var matrix = new ColorMatrix(newColorMatrix);
         var disabledImageAttr = new ImageAttributes();
         disabledImageAttr.ClearColorKey();
         disabledImageAttr.SetColorMatrix(matrix);
         _imageButton.Image = new Bitmap(Image.Width, Image.Height);
         using (Graphics gr = Graphics.FromImage(_imageButton.Image))
         {
             gr.DrawImage(Image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height,
                          GraphicsUnit.Pixel, disabledImageAttr);
         }
     }
     _imageButton.ImageAlign = ImageAlign;
     _imageButton.ImageIndex = ImageIndex;
     _imageButton.ImageKey = ImageKey;
     _imageButton.ImageList = ImageList;
     _imageButton.Padding = Padding;
     _imageButton.Size = Size;
     _imageButton.Text = Text;
     _imageButton.TextAlign = TextAlign;
     _imageButton.TextImageRelation = TextImageRelation;
     _imageButton.UseCompatibleTextRendering = UseCompatibleTextRendering;
     _imageButton.UseMnemonic = UseMnemonic;
     _imageButton.ResumeLayout();
     InvokePaint(_imageButton, pevent);
     if (_imageButton.Image != null && _imageButton.Image != Image)
     {
         _imageButton.Image.Dispose();
         _imageButton.Image = null;
     }
 }
        internal static void DrawImageDisabled(Graphics graphics, Image image, Rectangle imageBounds, Color background, bool unscaledImage) {
            if (graphics == null) {
                throw new ArgumentNullException("graphics");
            }
            if (image == null) {
                throw new ArgumentNullException("image");
            }
#if GRAYSCALE_DISABLED
            Size imageSize = image.Size;

            if (disabledImageAttr == null) {
                // This is how I came up with this somewhat random ColorMatrix.
                // Its set to resemble Office10 commandbars, but still be able to
                // deal with hi-color (256+) icons and images.
                //
                // The idea is to scale everything down (more than just a grayscale does,
                // therefore the small numbers in the scaling part of matrix)
                // White -> some shade of gray &
                // Black -> Black
                //
                // Second part of the matrix is to translate everything, so all colors are
                // a bit brigher.
                // Grays become lighter and washed out looking
                // Black becomes a shade of gray as well.
                //
                // btw, if you do come up with something better let me know - [....]
                
                float[][] array = new float[5][];
                    array[0] = new float[5] {0.2125f, 0.2125f, 0.2125f, 0, 0};
                array[1] = new float[5] {0.2577f, 0.2577f, 0.2577f, 0, 0};
                array[2] = new float[5] {0.0361f, 0.0361f, 0.0361f, 0, 0};
                array[3] = new float[5] {0,       0,       0,       1, 0};
                array[4] = new float[5] {0.38f,   0.38f,   0.38f,   0, 1};

                ColorMatrix grayMatrix = new ColorMatrix(array);

                disabledImageAttr = new ImageAttributes();
                disabledImageAttr.ClearColorKey();
                disabledImageAttr.SetColorMatrix(grayMatrix);
            }


            if (unscaledImage) {
                using (Bitmap bmp = new Bitmap(image.Width, image.Height)) {
                    using (Graphics g = Graphics.FromImage(bmp)) {
                        g.DrawImage(image, 
                                   new Rectangle(0, 0, imageSize.Width, imageSize.Height),
                                   0, 0, imageSize.Width, imageSize.Height,
                                   GraphicsUnit.Pixel, 
                                   disabledImageAttr);
                    }
                    graphics.DrawImageUnscaled(bmp, imageBounds);
                }
            }
            else {
                graphics.DrawImage(image, 
                                   imageBounds, 
                                   0, 0, imageSize.Width, imageSize.Height,
                                   GraphicsUnit.Pixel, 
                                   disabledImageAttr);
            }
#else


            // This is remarkably simple -- make a monochrome version of the image, draw once
            // with the button highlight color, then a second time offset by one pixel
            // and in the button shadow color.
            // Technique borrowed from comctl Toolbar.

            Bitmap bitmap;
            bool disposeBitmap = false;
            if (image is Bitmap)
                bitmap = (Bitmap) image;
            else {
                // #37659 -- metafiles can have extremely high resolutions,
                // so if we naively turn them into bitmaps, the performance will be very poor.
                // bitmap = new Bitmap(image);

                GraphicsUnit units = GraphicsUnit.Display;
                RectangleF bounds = image.GetBounds(ref units);
                bitmap = new Bitmap((int) (bounds.Width * graphics.DpiX / image.HorizontalResolution),
                                    (int) (bounds.Height * graphics.DpiY / image.VerticalResolution));

                Graphics bitmapGraphics = Graphics.FromImage(bitmap);
                bitmapGraphics.Clear(Color.Transparent);
                bitmapGraphics.DrawImage(image, 0, 0, image.Size.Width, image.Size.Height);
                bitmapGraphics.Dispose();

                disposeBitmap = true;
            }
            
            Color highlight = ControlPaint.LightLight(background);
            Bitmap monochrome = MakeMonochrome(bitmap, highlight);
            graphics.DrawImage(monochrome, new Rectangle(imageBounds.X + 1, imageBounds.Y + 1, imageBounds.Width, imageBounds.Height));
            monochrome.Dispose();

            Color shadow = ControlPaint.Dark(background);
            monochrome = MakeMonochrome(bitmap, shadow);
            graphics.DrawImage(monochrome, imageBounds);
            monochrome.Dispose();

            if (disposeBitmap)
                bitmap.Dispose();
#endif
        }
Example #9
0
		private static ImageAttributes GetDisabledAttributes()
		{
			float[][] array = new float[5][];
			array[0] = new float[5] {0.5f,  0.5f,  0.5f,  0.0f,  0.0f};
			array[1] = new float[5] {0.5f,  0.5f,  0.5f,  0.0f,  0.0f};
			array[2] = new float[5] {0.5f,  0.5f,  0.5f,  0.0f,  0.0f};
			array[3] = new float[5] {0.0f,  0.0f,  0.0f,  1.0f,  0.0f};
			array[4] = new float[5] {0.0f,  0.0f,  0.0f,  0.0f,  1.0f};
			//ColorMatrix grayMatrix = new ColorMatrix(array);
			ColorMatrix grayMatrix = new ColorMatrix();
			grayMatrix.Matrix00 = 1/3f; 
			grayMatrix.Matrix01 = 1/3f; 
			grayMatrix.Matrix02 = 1/3f; 
			grayMatrix.Matrix10 = 1/3f; 
			grayMatrix.Matrix11 = 1/3f; 
			grayMatrix.Matrix12 = 1/3f; 
			grayMatrix.Matrix20 = 1/3f; 
			grayMatrix.Matrix21 = 1/3f; 
			grayMatrix.Matrix22 = 1/3f;
			grayMatrix.Matrix33 = .5f; // Alpha-channel

			ImageAttributes darkImageAttr = new ImageAttributes();
			darkImageAttr.ClearColorKey();
			darkImageAttr.SetColorMatrix(grayMatrix);
			return darkImageAttr;
		}
Example #10
0
		private static ImageAttributes GetDarkAttributes()
		{
			float[][] array = new float[5][];
//			array[0] = new float[5] {1, 0, 0, 0, 0};
//			array[1] = new float[5] {0, 1, 0, 0, 0};
//			array[2] = new float[5] {0, 0, 1, 0, 0};
//			array[3] = new float[5] {0, 0, 1, 0, 0};
//			array[4] = new float[5] {.5f, .5f, .5f, 0, 1};
			array[0] = new float[5] {.65f, 0, 0, 0, 0};
			array[1] = new float[5] {0, .65f, 0, 0, 0};
			array[2] = new float[5] {0, 0, .65f, 0, 0};
			array[3] = new float[5] {0, 0, 0, 1, 0};
			array[4] = new float[5] {0, 0, 0, 0, .65f};
			ColorMatrix grayMatrix = new ColorMatrix(array);
			ImageAttributes darkImageAttr = new ImageAttributes();
			darkImageAttr.ClearColorKey();
			darkImageAttr.SetColorMatrix(grayMatrix);
			return darkImageAttr;
		}
Example #11
0
		private void PaintButton(ItemPaintArgs pa, SystemButton btn, Rectangle r)
		{
			System.Drawing.Graphics g=pa.Graphics;

			if(this.IsThemed)
			{
				System.Windows.Forms.Control container=this.ContainerControl as System.Windows.Forms.Control;
				if(container!=null)
				{
					ThemeWindow theme=pa.ThemeWindow;
					ThemeWindowParts part=ThemeWindowParts.MdiMinButton;
					ThemeWindowStates state=ThemeWindowStates.ButtonNormal;
					switch(btn)
					{
						case SystemButton.Close:
						{
							part=ThemeWindowParts.MdiCloseButton;
							break;
						}
						case SystemButton.Help:
						{
							part=ThemeWindowParts.MdiHelpButton;
							break;
						}
						case SystemButton.Restore:
						{
							part=ThemeWindowParts.MdiRestoreButton;
							break;
						}
					}
					if(btn==m_MouseDown)
						state=ThemeWindowStates.ButtonPushed;
					else if(btn==m_MouseOver)
						state=ThemeWindowStates.ButtonHot;

                    theme.DrawBackground(g,part,state,r);
					return;
				}
			}

			// Draw state if any
			if(btn==m_MouseDown)
			{
				if(pa.Colors.ItemPressedBackground2.IsEmpty)
					g.FillRectangle(new SolidBrush(pa.Colors.ItemPressedBackground),r);
				else
				{
					System.Drawing.Drawing2D.LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(r,pa.Colors.ItemPressedBackground,pa.Colors.ItemPressedBackground2,pa.Colors.ItemPressedBackgroundGradientAngle);
					g.FillRectangle(gradient,r);
					gradient.Dispose();
				}
				NativeFunctions.DrawRectangle(g,SystemPens.Highlight,r);
			}
			else if(btn==m_MouseOver)
			{
				if(!pa.Colors.ItemHotBackground2.IsEmpty)
				{
					System.Drawing.Drawing2D.LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(r,pa.Colors.ItemHotBackground,pa.Colors.ItemHotBackground2,pa.Colors.ItemHotBackgroundGradientAngle);
					g.FillRectangle(gradient,r);
					gradient.Dispose();
				}
				else
					g.FillRectangle(new SolidBrush(pa.Colors.ItemHotBackground),r);
				NativeFunctions.DrawRectangle(g,new Pen(pa.Colors.ItemHotBorder),r);
			}

            using (Bitmap bmp = GetButtonBitmap(g, btn, r, pa.Colors))
            {
                if (btn == SystemButton.Minimize && !m_MinimizeEnabled ||
                    btn == SystemButton.Restore && !m_RestoreEnabled ||
                    btn == SystemButton.Close && !m_CloseEnabled)
                {
                    float[][] array = new float[5][];
                    array[0] = new float[5] { 0, 0, 0, 0, 0 };
                    array[1] = new float[5] { 0, 0, 0, 0, 0 };
                    array[2] = new float[5] { 0, 0, 0, 0, 0 };
                    array[3] = new float[5] { .5f, .5f, .5f, .5f, 0 };
                    array[4] = new float[5] { 0, 0, 0, 0, 0 };
                    System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
                    System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes();
                    disabledImageAttr.ClearColorKey();
                    disabledImageAttr.SetColorMatrix(grayMatrix);
                    g.DrawImage(bmp, r, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, disabledImageAttr);
                }
                else
                {
                    if (btn == m_MouseDown)
                        r.Offset(1, 1);
                    g.DrawImageUnscaled(bmp, r);
                }
            }
		}
Example #12
0
        //=====================================================================

        /// <summary>
        /// Default constructor
        /// </summary>
        public ImageMap()
		{
            // Set the value of the double-buffering style bits to true
            this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);
            this.UpdateStyles();

			InitializeComponent();

			gPanel = Graphics.FromHwnd(this.Handle);

            activeArea = mouseArea = -1;
            areaCursor = Cursors.Hand;
            nonAreaCursor = Cursors.Default;
            centerImage = true;
			pathData = new GraphicsPath();

            // Create the disabled image attributes on first use
            if(iaDisabled == null)
            {
                float[][] afColorMatrix = new float[5][];

                afColorMatrix[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f };
                afColorMatrix[1] = new float[5] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f };
                afColorMatrix[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f };
                afColorMatrix[3] = new float[5] { 0f, 0f, 0f, 1f, 0f };
                afColorMatrix[4] = new float[5] { 0.38f, 0.38f, 0.38f, 0f, 1f};

                iaDisabled = new ImageAttributes();
                iaDisabled.ClearColorKey();
                iaDisabled.SetColorMatrix(new ColorMatrix(afColorMatrix));
            }
		}