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


C# ImageAttributes.SetColorMatrix方法代码示例

本文整理汇总了C#中System.Drawing.Imaging.ImageAttributes.SetColorMatrix方法的典型用法代码示例。如果您正苦于以下问题:C# ImageAttributes.SetColorMatrix方法的具体用法?C# ImageAttributes.SetColorMatrix怎么用?C# ImageAttributes.SetColorMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Imaging.ImageAttributes的用法示例。


在下文中一共展示了ImageAttributes.SetColorMatrix方法的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: 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

示例3: GetImage

        internal static Image GetImage(Image originalImage, float opacity)
        {
            Image image = new Bitmap(originalImage);

            using (var g = Graphics.FromImage(image)) {
                using (var attributes = new ImageAttributes()) {
                    var matrix = new ColorMatrix { Matrix40 = opacity, Matrix41 = opacity, Matrix42 = opacity };
                    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                    attributes.SetColorMatrix(matrix);
                    g.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
                }
            }
            return image;
        }
开发者ID:jmcadams,项目名称:vplus,代码行数:14,代码来源:BgImage.cs

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: adjustBitmap

        /// <summary>
        /// change brightness, contrast and/or gamma of a bitmap
        /// (see http://stackoverflow.com/questions/15408607/adjust-brightness-contrast-and-gamma-of-an-image)
        /// </summary>
        /// <param name="originalImage">image to process</param>
        /// <param name="brightness">new brightness (1.0 = no changes, 0.0 to 2.0)</param>
        /// <param name="contrast">new contrast (1.0 = no changes)</param>
        /// <param name="gamma">new gamma (1.0 = no changes)</param>
        /// <returns></returns>
        static internal Bitmap adjustBitmap(Bitmap originalImage, float brightness = 1.0f, float contrast = 1.0f, float gamma = 1.0f)
        {
            Bitmap adjustedImage;
            ImageAttributes imageAttributes;
            Graphics g;
            float adjustedBrightness;

            adjustedBrightness = brightness - 1.0f;

            // create matrix that will brighten and contrast the image
            float[][] ptsArray ={
                    new float[] {contrast, 0, 0, 0, 0},     // scale red
                    new float[] {0, contrast, 0, 0, 0},     // scale green
                    new float[] {0, 0, contrast, 0, 0},     // scale blue
                    new float[] {0, 0, 0, 1.0f, 0},         // don't scale alpha
                    new float[] {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1}};

            imageAttributes = new ImageAttributes();
            imageAttributes.ClearColorMatrix();
            imageAttributes.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            imageAttributes.SetGamma(gamma, ColorAdjustType.Bitmap);

            adjustedImage   = new Bitmap(originalImage.Width, originalImage.Height);
            g               = Graphics.FromImage(adjustedImage);

            g.DrawImage(originalImage, new Rectangle(0,0,adjustedImage.Width,adjustedImage.Height),
                        0,0,originalImage.Width,originalImage.Height,
                        GraphicsUnit.Pixel, imageAttributes);

            g.Dispose();

            return adjustedImage;
        }
开发者ID:Duke-Jones,项目名称:ED-IBE,代码行数:42,代码来源:RNGraphics.cs

示例9: MakeGrayscale

        public static Bitmap MakeGrayscale(Bitmap original)
        {
            Bitmap newBitmap = new Bitmap(original.Width, original.Height);

            Graphics g = Graphics.FromImage(newBitmap);

            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}
               });

            ImageAttributes attributes = new ImageAttributes();

            attributes.SetColorMatrix(colorMatrix);

            g.DrawImage(original, new System.Drawing.Rectangle(0, 0, original.Width, original.Height),
               0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);

            g.Dispose();
            return newBitmap;
        }
开发者ID:FloRest,项目名称:OCMDR,代码行数:26,代码来源:MainWindow.xaml.cs

示例10: TransformImage

        /// <summary>
        /// Processes the image.
        /// </summary>
        /// <param name="source">The current image to process</param>
        /// <param name="destination">The new Image to return</param>
        /// <returns>
        /// The processed <see cref="System.Drawing.Bitmap"/>.
        /// </returns>
        public override Bitmap TransformImage(Image source, Image destination)
        {
            using (Graphics graphics = Graphics.FromImage(destination))
            {
                using (ImageAttributes attributes = new ImageAttributes())
                {
                    attributes.SetColorMatrix(this.Matrix);

                    Rectangle rectangle = new Rectangle(0, 0, source.Width, source.Height);

                    graphics.DrawImage(source, rectangle, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);
                }
            }

            // Fade the contrast
            destination = Adjustments.Contrast(destination, -25);

            // Add a glow to the image.
            destination = Effects.Glow(destination, Color.FromArgb(70, 255, 153, 102));

            // Add a vignette to finish the effect.
            destination = Effects.Vignette(destination, Color.FromArgb(220, 102, 34, 0));

            return (Bitmap)destination;
        }
开发者ID:AlexSkarbo,项目名称:ImageProcessor,代码行数:33,代码来源:PolaroidMatrixFilter.cs

示例11: ColorShift

        public static Bitmap ColorShift(Image b, Color cs)
        {
            Bitmap bDest = new Bitmap(b.Width, b.Height, b.PixelFormat);

            // Create the ImageAttributes object and apply the ColorMatrix
            ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
            ColorMatrix shiftMatrix = 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[] {cs.R/255f, cs.G/255f, cs.B/255f, 0, 1}
            });
            attributes.SetColorMatrix(shiftMatrix);

            // Use a new Graphics object from the new image.
            using (Graphics g = Graphics.FromImage(bDest))
            {
                // Draw the original image using the ImageAttributes created above.
                g.DrawImage(b,
                            new Rectangle(0, 0, b.Width, b.Height),
                            0, 0, b.Width, b.Height,
                            GraphicsUnit.Pixel,
                            attributes);
            }

            return bDest;
        }
开发者ID:rraguso,项目名称:protone-suite,代码行数:28,代码来源:ImageProcessing.cs

示例12: Brightness

        public static Bitmap Brightness(Image b, float brightness)
        {
            Bitmap bDest = new Bitmap(b.Width, b.Height, b.PixelFormat);

            float adjustedBrightness = brightness - 1.0f;

            // Create the ImageAttributes object and apply the ColorMatrix
            ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes();
            ColorMatrix brightnessMatrix = new ColorMatrix(new float[][]{
                new float[] {1, 0, 0, 0, 0},
                new float[] {0, 1, 0, 0, 0},
                new float[] {0, 0, 0, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {brightness, brightness, brightness, 0, 1}
            });
            attributes.SetColorMatrix(brightnessMatrix);

            // Use a new Graphics object from the new image.
            using (Graphics g = Graphics.FromImage(bDest))
            {
                // Draw the original image using the ImageAttributes created above.
                g.DrawImage(b,
                            new Rectangle(0, 0, b.Width, b.Height),
                            0, 0, b.Width, b.Height,
                            GraphicsUnit.Pixel,
                            attributes);
            }

            return bDest;
        }
开发者ID:rraguso,项目名称:protone-suite,代码行数:30,代码来源:ImageProcessing.cs

示例13: ImageToGrayscale

 /// <summary>
 /// Converts image to a grayscale image
 /// </summary>
 public static Image ImageToGrayscale(Image image)
 {
     try
     {
         Bitmap bitmap = new Bitmap(image.Width, image.Height);
         Graphics graphics = Graphics.FromImage(bitmap);
         ColorMatrix matrix = 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 attributes = new ImageAttributes();
         attributes.SetColorMatrix(matrix);
         graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
         graphics.Dispose(); // Dispose temp graphics
         return (Image)bitmap;
     }
     catch (Exception ex)
     {
         ErrorManager.ShowError(ex);
         return image;
     }
 }
开发者ID:heon21st,项目名称:flashdevelop,代码行数:28,代码来源:ImageKonverter.cs

示例14: InvertImage

        internal static Image InvertImage(Image myImage)
        {
            var invertedBmp = new Bitmap(myImage.Width, myImage.Height);

            //Setup color matrix
            var clrMatrix =
                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}
                });

            using (var attr = new ImageAttributes())
            {
                //Attach matrix to image attributes
                attr.SetColorMatrix(clrMatrix);

                using (var g = Graphics.FromImage(invertedBmp))
                {
                    g.DrawImage(myImage, new Rectangle(0, 0, myImage.Width, myImage.Height), 0, 0, myImage.Width,
                        myImage.Height, GraphicsUnit.Pixel, attr);
                }
            }

            return invertedBmp;
        }
开发者ID:rajeshwarn,项目名称:TornadoCapture,代码行数:26,代码来源:ImageManipulation.cs

示例15: Perform

        public override Bitmap Perform(Bitmap bitmap)
        {
            float contrastAdjusted = Contrast / 1000f + 1.0f;

            EnsurePixelFormat(ref bitmap);
            using (var g = Graphics.FromImage(bitmap))
            {
                var attrs = new ImageAttributes();
                attrs.SetColorMatrix(new ColorMatrix
                {
                    Matrix00 = contrastAdjusted,
                    Matrix11 = contrastAdjusted,
                    Matrix22 = contrastAdjusted
                });
                g.DrawImage(bitmap,
                    new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                    0,
                    0,
                    bitmap.Width,
                    bitmap.Height,
                    GraphicsUnit.Pixel,
                    attrs);
            }
            return bitmap;
        }
开发者ID:lapuinka,项目名称:naps2,代码行数:25,代码来源:ContrastTransform.cs


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