当前位置: 首页>>代码示例>>C#>>正文


C# Imaging.ColorMatrix类代码示例

本文整理汇总了C#中System.Drawing.Imaging.ColorMatrix的典型用法代码示例。如果您正苦于以下问题:C# ColorMatrix类的具体用法?C# ColorMatrix怎么用?C# ColorMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ColorMatrix类属于System.Drawing.Imaging命名空间,在下文中一共展示了ColorMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply

        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);
        }
开发者ID:Grifs99,项目名称:ShareX,代码行数:29,代码来源:GrayscaleFilter.cs

示例2: AdjustBrightness

        public static Bitmap AdjustBrightness(this Image Image, Color contrastMultiplier, Color brightnessBonus)
        {
            var TempBitmap = Image;
            var NewBitmap = new Bitmap(TempBitmap.Width, TempBitmap.Height);
            var NewGraphics = Graphics.FromImage(NewBitmap);
            float[][] FloatColorMatrix = {
                                             new[] { contrastMultiplier.R/255.0f, 0, 0, 0, 0 }, new[] { 0, contrastMultiplier.G/255.0f, 0, 0, 0 },
                                             new[] { 0, 0, contrastMultiplier.B/255.0f, 0, 0 }, new float[] { 0, 0, 0, 1, 0 },
                                             new[] { brightnessBonus.R/255.0f, brightnessBonus.G/255.0f, brightnessBonus.B/255.0f, 1, 1 }
                                         };

            var NewColorMatrix = new ColorMatrix(FloatColorMatrix);
            var Attributes = new ImageAttributes();
            Attributes.SetColorMatrix(NewColorMatrix);
            NewGraphics.DrawImage(TempBitmap,
                                  new Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height),
                                  0,
                                  0,
                                  TempBitmap.Width,
                                  TempBitmap.Height,
                                  GraphicsUnit.Pixel,
                                  Attributes);
            Attributes.Dispose();
            NewGraphics.Dispose();
            return NewBitmap;
        }
开发者ID:Jamanno,项目名称:Zero-K-Infrastructure,代码行数:26,代码来源:Images.cs

示例3: MakeGrayscaleWithColorMatrix

 private Bitmap MakeGrayscaleWithColorMatrix(Bitmap original)
 {
     //create a blank bitmap the same size as original
     Bitmap newBitmap = new Bitmap(original.Width, original.Height);
     //get a graphics object from the new image
     Graphics g = Graphics.FromImage(newBitmap);
     //create the grayscale ColorMatrix
     ColorMatrix colorMatrix = new ColorMatrix(
        new float[][]
       {
          new float[] {.3f, .3f, .3f, 0, 0},
          new float[] {.59f, .59f, .59f, 0, 0},
          new float[] {.11f, .11f, .11f, 0, 0},
          new float[] {0, 0, 0, 1, 0},
          new float[] {0, 0, 0, 0, 1}
       });
     //create some image attributes
     ImageAttributes attributes = new ImageAttributes();
     //set the color matrix attribute
     attributes.SetColorMatrix(colorMatrix);
     //draw the original image on the new image
     //using the grayscale color matrix
     g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
        0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
     //dispose the Graphics object
     g.Dispose();
     return newBitmap;
 }
开发者ID:bhabesh7,项目名称:bhabeshgitprojects,代码行数:28,代码来源:ImageViewModel.cs

示例4: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            begin = DateTime.Now.Ticks;
            
            Bitmap currentBitmap = new Bitmap(pictureBox1.Image);
            Graphics g = Graphics.FromImage(currentBitmap);

            ImageAttributes ia = new ImageAttributes();

            float[][] colorMatrix =   {
                new float[] {0.299f,   0.299f,   0.299f,   0,   0},
                new float[]   {0.587f,   0.587f,   0.587f,   0,   0},
                new float[]   {0.114f,   0.114f,   0.114f,   0,   0},
                new float[]   {0,   0,   0,   1,   0},
                new float[]   {0,   0,   0,   0,   1}
                                      };

            ColorMatrix cm = new ColorMatrix(colorMatrix);

            ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            g.DrawImage(currentBitmap, new Rectangle(0, 0, currentBitmap.Width, currentBitmap.Height), 0, 0, currentBitmap.Width, currentBitmap.Height, GraphicsUnit.Pixel, ia);

            pictureBox1.Image = currentBitmap;

            g.Dispose();
            end = DateTime.Now.Ticks;
            label1.Text = (end - begin) / 1000 + "毫秒";
        }
开发者ID:MaisonWan,项目名称:PhotoHuntHelper,代码行数:29,代码来源:FormTest.cs

示例5: SetImageOpacity

        public static Image SetImageOpacity(Image image, float opacity)
        {
            try
            {
                //create a Bitmap the size of the image provided
                var bmp = new Bitmap(image.Width, image.Height);

                //create a graphics object from the image
                using (var gfx = Graphics.FromImage(bmp))
                {
                    //create a color matrix object
                    var matrix = new ColorMatrix();

                    //set the opacity
                    matrix.Matrix33 = opacity;

                    //create image attributes
                    var attributes = new ImageAttributes();

                    //set the color(opacity) of the image
                    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                    //now draw the image
                    gfx.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, image.Width, image.Height,
                        GraphicsUnit.Pixel, attributes);
                }
                return bmp;
            }
            catch
            {
                return null;
            }
        }
开发者ID:rivnam,项目名称:AudioSwitcher_v1,代码行数:33,代码来源:ImageHelper.cs

示例6: Offset

        public Bitmap Offset(Bitmap bmpSource, Color clrScaleColor)
        {
            Bitmap bmpTemp = new Bitmap(bmpSource.Width, bmpSource.Height); //Create Temporary Bitmap To Work With

            ImageAttributes iaImageProps = new ImageAttributes(); //Contains information about how bitmap and metafile colors are manipulated during rendering.

            CMOffset = new ColorMatrix(new float[][] {
            new float[] {1,0,0,0,0},
            new float[] {0,1,0,0,0},
            new float[] {0,0,1,0,0},
            new float[] {0,0,0,1,0},
            new float[] {
                (float)clrScaleColor.R / 255,
                (float)clrScaleColor.G / 255,
                (float)clrScaleColor.B / 255,
                0,
                1
            }
            });
            iaImageProps.SetColorMatrix(combineColorMatrix()); //Apply Matrix

            Graphics grpGraphics = Graphics.FromImage(bmpTemp); //Create Graphics Object and Draw Bitmap Onto Graphics Object

            grpGraphics.DrawImage(bmpSource, new Rectangle(0, 0, bmpSource.Width, bmpSource.Height), 0, 0, bmpSource.Width, bmpSource.Height, GraphicsUnit.Pixel, iaImageProps);

            return bmpTemp;
        }
开发者ID:wofsauge,项目名称:IsaacAnimator,代码行数:27,代码来源:Coloring.cs

示例7: ExecuteFilter

        /// <summary>
        /// Executes this filter on the input image and returns the result
        /// </summary>
        /// <param name="inputImage">input image</param>
        /// <returns>transformed image</returns>
        public override Image ExecuteFilter(Image inputImage)
        {
            ///Reference from http://www.bobpowell.net/grayscale.htm
              Bitmap bm = new Bitmap(inputImage.Width, inputImage.Height);
              Graphics g = Graphics.FromImage(bm);
              ColorMatrix cm;

              if (_isBright)
              {
            cm = new ColorMatrix(new float[][]{   new float[]{0.5f,0.5f,0.5f,0,0},
                                  new float[]{0.5f,0.5f,0.5f,0,0},
                                  new float[]{0.5f,0.5f,0.5f,0,0},
                                  new float[]{0,0,0,1,0,0},
                                  new float[]{0,0,0,0,1,0},
                                  new float[]{0,0,0,0,0,1}});
              }
              else
              {

            //Gilles Khouzams colour corrected grayscale shear
            cm = new ColorMatrix(new float[][]{   new float[]{0.3f,0.3f,0.3f,0,0},
                                new float[]{0.59f,0.59f,0.59f,0,0},
                                new float[]{0.11f,0.11f,0.11f,0,0},
                                new float[]{0,0,0,1,0,0},
                                new float[]{0,0,0,0,1,0},
                                new float[]{0,0,0,0,0,1}});
              }

              ImageAttributes ia = new ImageAttributes();
              ia.SetColorMatrix(cm);
              g.DrawImage(inputImage, new Rectangle(0, 0, inputImage.Width, inputImage.Height), 0, 0, inputImage.Width, inputImage.Height, GraphicsUnit.Pixel, ia);
              g.Dispose();
              return bm;
        }
开发者ID:Epitomy,项目名称:CMS,代码行数:39,代码来源:BlackAndWhite.cs

示例8: grayScale

        // Obraz w skali szarości;
        internal void grayScale(MyBitmap myBitmap)
        {
            myBitmap.PreviousBitmap = (Bitmap)myBitmap.CurrentBitmap.Clone();
            //Srednia skladowych       // Wykorzystanie modelu YUV
            const float rMod = 0.333f; //rMod = 0.299f;
            const float gMod = 0.333f; //gMod = 0.587f;
            const float bMod = 0.333f; //bMod = 0.114f;
            Graphics g = Graphics.FromImage(myBitmap.CurrentBitmap);

            ColorMatrix colorMatrix = new ColorMatrix(new[]
            {
                new[] {rMod, rMod, rMod, 0, 1},
                new[] {gMod, gMod, gMod, 0, 1},
                new[] {bMod, bMod, bMod, 0, 1},
                new[] {0.0f, 0.0f, 0.0f, 1, 1},
                new[] {0.0f, 0.0f, 0.0f, 0, 1}
            });

            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(colorMatrix);
            int x = myBitmap.BitmapInfo.SizeX;
            int y = myBitmap.BitmapInfo.SizeY;
            g.DrawImage(myBitmap.CurrentBitmap, new Rectangle(0, 0, x, y), 0, 0, x, y, GraphicsUnit.Pixel, attributes);
            //myBitmap.updateArrays();
            g.Dispose();
        }
开发者ID:radol91,项目名称:BitMapEditorSolution,代码行数:27,代码来源:MyBitmapEditor.cs

示例9: DrawEffectImage

        public override void DrawEffectImage(Bitmap current, Bitmap next, EffectingPanel effecingPanel)
        {
            Bitmap doubleBufferingBitmap = null;    // ダブルバッファリング用画面
            Graphics bg = null;                     // ダブルバッファリング用画面描画用Graphics

            SolidBrush solidBrush = null;
            Rectangle rectangle;

            ColorMatrix colorMatrix = null;
            ImageAttributes imageAttributes = null;

            try
            {
                doubleBufferingBitmap = new Bitmap(current);
                bg = Graphics.FromImage(doubleBufferingBitmap);

                solidBrush = new SolidBrush(System.Drawing.Color.Black);
                rectangle = new Rectangle(0, 0, current.Width, current.Height);

                colorMatrix = new ColorMatrix();
                imageAttributes = new ImageAttributes();

                ResetInterval();

                // フェードアウト
                for (float alpha = 0.9f; alpha >= 0.0f; alpha -= 0.05f)
                {
                    bg.FillRectangle(solidBrush, rectangle);
                    colorMatrix.Matrix33 = alpha;
                    imageAttributes.SetColorMatrix(colorMatrix);
                    bg.DrawImage(current, rectangle, 0, 0, doubleBufferingBitmap.Width, doubleBufferingBitmap.Height, GraphicsUnit.Pixel, imageAttributes);

                    Thread.Sleep(10);

                    effecingPanel.pictureBox.Image = doubleBufferingBitmap;
                    effecingPanel.pictureBox.Refresh();

                    DoEventAtIntervals();
                }
                for (float alpha = 0.0f; alpha <= 1.0f; alpha += 0.05f)
                {
                    bg.FillRectangle(solidBrush, rectangle);
                    colorMatrix.Matrix33 = alpha;
                    imageAttributes.SetColorMatrix(colorMatrix);
                    bg.DrawImage(next, rectangle, 0, 0, doubleBufferingBitmap.Width, doubleBufferingBitmap.Height, GraphicsUnit.Pixel, imageAttributes);

                    Thread.Sleep(10);

                    effecingPanel.pictureBox.Image = doubleBufferingBitmap;
                    effecingPanel.pictureBox.Refresh();

                    DoEventAtIntervals();
                }
                bg.Dispose();
            }
            catch (SystemException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:chanpi,项目名称:FormSample,代码行数:60,代码来源:EPFadingEffect.cs

示例10: ToNegative

        /// <summary>
        /// To the negative.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static Bitmap ToNegative(this Bitmap source)
        {
            //create a blank bitmap the same size as original
            Bitmap newBitmap = new Bitmap(source.Width, source.Height);

            //get a graphics object from the new image
            Graphics g = Graphics.FromImage(newBitmap);

            // create the negative color matrix
            ColorMatrix colorMatrix = new ColorMatrix(
               new float[][]
   {
      new float[] {-1, 0, 0, 0, 0},
      new float[] {0, -1, 0, 0, 0},
      new float[] {0, 0, -1, 0, 0},
      new float[] {0, 0, 0, 1, 0},
      new float[] {1, 1, 1, 0, 1}
   });

            // create some image attributes
            ImageAttributes attributes = new ImageAttributes();

            attributes.SetColorMatrix(colorMatrix);

            g.DrawImage(source, new Rectangle(0, 0, source.Width, source.Height),
                        0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);

            //dispose the Graphics object
            g.Dispose();

            return newBitmap;
        }
开发者ID:sybold,项目名称:AcExtensionLibrary,代码行数:37,代码来源:BitmapExtensions.cs

示例11: Trank

 public ImageAttributes Trank(Bitmap btm, int Alphas)
 {
     Bitmap box = (Bitmap) btm.Clone();
     Graphics.FromImage(box);
     float Alpha = ((float) Alphas) / 100f;
     float[][] CS_0_0000 = new float[5][];
     float[] CS_0_0001 = new float[5];
     CS_0_0001[0] = 1f;
     CS_0_0000[0] = CS_0_0001;
     float[] CS_0_0002 = new float[5];
     CS_0_0002[1] = 1f;
     CS_0_0000[1] = CS_0_0002;
     float[] CS_0_0003 = new float[5];
     CS_0_0003[2] = 1f;
     CS_0_0000[2] = CS_0_0003;
     float[] CS_0_0004 = new float[5];
     CS_0_0004[3] = Alpha;
     CS_0_0000[3] = CS_0_0004;
     float[] CS_0_0005 = new float[5];
     CS_0_0005[4] = 1f;
     CS_0_0000[4] = CS_0_0005;
     float[][] matrixltems = CS_0_0000;
     ColorMatrix colorMatrix = new ColorMatrix(matrixltems);
     ImageAttributes ImageAtt = new ImageAttributes();
     ImageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
     return ImageAtt;
 }
开发者ID:zhushengwen,项目名称:example-zhushengwen,代码行数:27,代码来源:SkinFormProfessionalRenderer.cs

示例12: GetDragCursor

		private Cursor GetDragCursor(Image image)
		{
			if (image == null) return Cursors.Default;
			image = ResizeImage(imageListView.ThumbnailSize.Width, image);
			var imageBounds = new Rectangle(new Point(0, 0), image.Size);
			var result = new Bitmap(imageBounds.Width, imageBounds.Height);
			var resultGraphics = Graphics.FromImage(result);
			float[][] matrixItems =
			{
				new float[] { 1, 0, 0, 0, 0 },
				new float[] { 0, 1, 0, 0, 0 },
				new float[] { 0, 0, 1, 0, 0 },
				new[] { 0, 0, 0, 0.7f, 0 },
				new float[] { 0, 0, 0, 0, 1 }
			};
			var colorMatrix = new ColorMatrix(matrixItems);
			var imageAttributes = new ImageAttributes();
			imageAttributes.SetColorMatrix(
				colorMatrix,
				ColorMatrixFlag.Default,
				ColorAdjustType.Bitmap);
			resultGraphics.DrawImage(image, imageBounds, imageBounds.X, imageBounds.Y, imageBounds.Width, imageBounds.Height, GraphicsUnit.Pixel, imageAttributes);
			var offset = new Point(imageBounds.Width / 2, imageBounds.Height / 2);
			return GridDragDropHelper.CreateCursor(result, offset);
		}
开发者ID:w01f,项目名称:VolgaTeam.Dashboard,代码行数:25,代码来源:CalendarHeaderSelector.cs

示例13: InvertColors

        public static Image InvertColors(Image image)
        {
            //create a blank bitmap the same size as original
            Bitmap newBitmap = new Bitmap(image.Width, image.Height);

            //get a graphics object from the new image
            Graphics g = Graphics.FromImage(newBitmap);

            // create the negative color matrix
            ColorMatrix colorMatrix = new ColorMatrix(new[]
            {
                new float[] {-1, 0, 0, 0, 0},
                new float[] {0, -1, 0, 0, 0},
                new float[] {0, 0, -1, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {1, 1, 1, 0, 1}
            });
            
            ImageAttributes attributes = new ImageAttributes();

            attributes.SetColorMatrix(colorMatrix);

            g.DrawImage(image, 
                        new Rectangle(0, 0, image.Width, image.Height), 
                        0, 0, 
                        image.Width, 
                        image.Height, 
                        GraphicsUnit.Pixel, 
                        attributes);
            
            g.Dispose();

            return newBitmap;
        }
开发者ID:AbabeiAndrei,项目名称:WProject,代码行数:34,代码来源:ImageHelper.Filtre.cs

示例14: SetBrightness

        public static Image SetBrightness(Image image, float brightness)
        {
            float b = brightness;
            ColorMatrix cm = new ColorMatrix(new[]
            {
                new[] {b, 0, 0,  0,  0},
                new[] {0, b, 0,  0,  0},
                new[] {0, 0, b,  0,  0},
                new[] {0, 0, 0, 1f,  0},
                new[] {0, 0, 0,  0, 1f}
            });

            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(cm);
            
            Point[] points =
            {
                new Point(0, 0),
                new Point(image.Width - 1, 0),
                new Point(0, image.Height - 1),
            };
            Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
            
            Bitmap bm = new Bitmap(image.Width, image.Height);
            using (Graphics gr = Graphics.FromImage(bm))
            {
                gr.DrawImage(image, points, rect,
                    GraphicsUnit.Pixel, attributes);
            }

            // Return the result.
            return bm;
        }
开发者ID:AbabeiAndrei,项目名称:WProject,代码行数:33,代码来源:ImageHelper.Filtre.cs

示例15: SetColorMatrices

		public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix gMatrix, ColorMatrixFlag mode, ColorAdjustType type)
		{
			clrMatrix = newColorMatrix;
			this.gMatrix = gMatrix;
			clrMatrixFlag = mode;
			clrAdjustType = type;
		}
开发者ID:carrie901,项目名称:mono,代码行数:7,代码来源:ImageAttributes.jvm.cs


注:本文中的System.Drawing.Imaging.ColorMatrix类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。