System.Drawing.Imaging.ImageAttributes.SetColorMatrix C# (CSharp) Method

SetColorMatrix() public method

public SetColorMatrix ( System.Drawing.Imaging.ColorMatrix newColorMatrix ) : void
newColorMatrix System.Drawing.Imaging.ColorMatrix
return void
		public void SetColorMatrix(ColorMatrix newColorMatrix)
		{
			SetColorMatrix(newColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Default);
		}

Same methods

ImageAttributes::SetColorMatrix ( System.Drawing.Imaging.ColorMatrix newColorMatrix, ColorMatrixFlag flags ) : void
ImageAttributes::SetColorMatrix ( System.Drawing.Imaging.ColorMatrix newColorMatrix, ColorMatrixFlag mode, ColorAdjustType type ) : void

Usage Example

示例#1
2
        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            ColorMatrix grayscaleMatrix = new ColorMatrix(new[] {
                new[] {.3f, .3f, .3f, 0, 0},
                new[] {.59f, .59f, .59f, 0, 0},
                new[] {.11f, .11f, .11f, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {0, 0, 0, 0, 1}
            });
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.SetColorMatrix(grayscaleMatrix);
                graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
            }
            graphics.Restore(state);
        }
All Usage Examples Of System.Drawing.Imaging.ImageAttributes::SetColorMatrix