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


C# ImageAttributes.ClearColorMatrix方法代码示例

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


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

示例1: AdjustRGBGamma

        /// <summary>
        /// Adjusts the red, green and blue parts of the image
        /// 
        /// Examples:
        /// Original image should be dark/black (main color RGB(51,51,51) and less)
        ///
        ///    blue (metro): 0,1,3,0.55
        ///    light grey: 1,1,1,0.35
        ///    white: 1,1,1,0.01
        ///    green: 0,2,0,0.75
        ///    red: 2,0,0,0.75
        /// </summary>
        /// <param name="img">Image</param>
        /// <param name="red">red part adjustment (>= 0.00, 1.0 = no changes)</param>
        /// <param name="green">red part adjustment (>= 0.00, 1.0 = no changes)</param>
        /// <param name="blue">blue part adjustment (>= 0.00, 1.0 = no changes)</param>
        /// <param name="gamma">Gamma adjustment (> 0.00, 1.0 = no changes)</param>
        /// <returns>the modified Image</returns>
        public static Image AdjustRGBGamma(this Image img, float red, float green, float blue, float gamma)
        {
            Bitmap bmp = new Bitmap(img.Width, img.Height);

            ImageAttributes imgAttributes = new ImageAttributes();

            ColorMatrix matrix = new ColorMatrix(
                new float[][] {
                new float[] { red, 0, 0, 0, 0 },
                new float[] { 0, green, 0, 0, 0 },
                new float[] { 0, 0, blue, 0, 0 },
                new float[] { 0, 0, 0, 1.0f, 0 },
                new float[] { 0, 0, 0, 0, 1 },
                });

            imgAttributes.ClearColorMatrix();
            imgAttributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            imgAttributes.SetGamma(gamma, ColorAdjustType.Bitmap);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height),
                    0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttributes);
            }

            return (Image)bmp;
        }
开发者ID:ajmd17,项目名称:apexengine-sharp,代码行数:45,代码来源:ImageEx.cs

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

示例3: AdjustImage

        public static Bitmap AdjustImage(Bitmap original, float brightness = 1.0f, float contrast = 1.0f, float gamma = 1.0f)
        {
            var adjustedImage = new Bitmap(original.Width, original.Height);

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

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

            using (var g = Graphics.FromImage(adjustedImage))
            {
                g.DrawImage(original, new Rectangle(Point.Empty, adjustedImage.Size), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, ia);
            }

            return adjustedImage;
        }
开发者ID:ipatalas,项目名称:D3Bit,代码行数:25,代码来源:ImageUtil.cs

示例4: Apply

        public static Image Apply(this ColorMatrix matrix, Image src, Image dest, Rectangle destRect)
        {
            using (Graphics g = Graphics.FromImage(dest))
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.ClearColorMatrix();
                ia.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                g.SetHighQuality();
                g.DrawImage(src, destRect, 0, 0, src.Width, src.Height, GraphicsUnit.Pixel, ia);
            }

            return dest;
        }
开发者ID:barsv,项目名称:ShareX,代码行数:13,代码来源:ColorMatrixManager.cs

示例5: ChangeGamma

        /// <param name="img"></param>
        /// <param name="value">1 = No change (Min 0.1, Max 5.0)</param>
        public static Image ChangeGamma(Image img, float value)
        {
            value = value.Between(0.1f, 5.0f);

            Bitmap bmp = img.CreateEmptyBitmap();

            using (Graphics g = Graphics.FromImage(bmp))
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.ClearColorMatrix();
                ia.SetGamma(value, ColorAdjustType.Bitmap);
                g.SetHighQuality();
                g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
            }

            return bmp;
        }
开发者ID:barsv,项目名称:ShareX,代码行数:19,代码来源:ColorMatrixManager.cs

示例6: OnPaint

        protected override void OnPaint(PaintEventArgs pe)
        {
            Graphics g = pe.Graphics;

            if (this.Enabled)
            {
                // draw background
                /*if(base.BackgroundImage != null)
                    g.DrawImage(base.BackgroundImage, 0, 0);*/

                // draw head
                if(head_image != null)
                    g.DrawImage(head_image, head_rect.X, head_rect.Y, head_image.Width, head_image.Height);
            }
            else
            {
                // disabled version of the thumb - same but dimmer
                float brightness = 1.0f;    // no change in brightness
                float contrast = 0.5f;      // half the contrast
                float gamma = 1.0f;         // no change in gamma
                float newBrightness = brightness - 1.0f;
                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[] {newBrightness, newBrightness, newBrightness, 0, 1}};

                ImageAttributes imageAttributes = new ImageAttributes();
                imageAttributes.ClearColorMatrix();
                imageAttributes.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                imageAttributes.SetGamma(gamma, ColorAdjustType.Bitmap);
                
                // draw background
                /*if(base.BackgroundImage != null)
                    g.DrawImage(base.BackgroundImage,
                        new Rectangle(0, 0, this.Width, this.Height),
                        0, 0, base.BackgroundImage.Width, base.BackgroundImage.Height,
                        GraphicsUnit.Pixel,
                        imageAttributes);*/

                // draw head
                if(head_image != null)
                    g.DrawImage(head_image,
                        new Rectangle(head_rect.X, head_rect.Y, head_image.Width, head_image.Height),
                        0, 0, head_image.Width, head_image.Height,
                        GraphicsUnit.Pixel,
                        imageAttributes);
 
                imageAttributes.Dispose();
                imageAttributes = null;
            }
        }
开发者ID:HosokawaKenchi,项目名称:powersdr-if-stage,代码行数:53,代码来源:PrettyTrackBar.cs

示例7: CreateAdjustAttributes

        /// <summary>
        /// Create ImageAttributes to modify
        /// </summary>
        /// <param name="brightness"></param>
        /// <param name="contrast"></param>
        /// <param name="gamma"></param>
        /// <returns>ImageAttributes</returns>
        public static ImageAttributes CreateAdjustAttributes(float brightness, float contrast, float gamma)
        {
            float adjustedBrightness = brightness - 1.0f;
            ColorMatrix applyColorMatrix = new ColorMatrix(
                    new float[][] {
                        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}
                    });

            //create some image attributes
            ImageAttributes attributes = new ImageAttributes();
            attributes.ClearColorMatrix();
            attributes.SetColorMatrix(applyColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            attributes.SetGamma(gamma, ColorAdjustType.Bitmap);
            return attributes;
        }
开发者ID:yuhongfang,项目名称:ShareX,代码行数:26,代码来源:ImageHelper.cs

示例8: ApplyColorMatrix

 /// <summary>
 /// Apply a color matrix by copying from the source to the destination
 /// </summary>
 /// <param name="source">Image to copy from</param>
 /// <param name="sourceRect">Rectangle to copy from</param>
 /// <param name="destRect">Rectangle to copy to</param>
 /// <param name="dest">Image to copy to</param>
 /// <param name="colorMatrix">ColorMatrix to apply</param>
 public static void ApplyColorMatrix(Bitmap source, Rectangle sourceRect, Bitmap dest, Rectangle destRect, ColorMatrix colorMatrix)
 {
     using (ImageAttributes imageAttributes = new ImageAttributes())
     {
         imageAttributes.ClearColorMatrix();
         imageAttributes.SetColorMatrix(colorMatrix);
         ApplyImageAttributes(source, sourceRect, dest, destRect, imageAttributes);
     }
 }
开发者ID:yuhongfang,项目名称:ShareX,代码行数:17,代码来源:ImageHelper.cs

示例9: ToWaterMark


//.........这里部分代码省略.........
             graphics.DrawString(this.WaterMarkText, font, new SolidBrush(Color.FromArgb(0x99, 0, 0, 0)), new PointF(x + 1f, y + 1f), format);
             graphics.DrawString(this.WaterMarkText, font, new SolidBrush(Color.FromArgb(this.Diaphaneity, 0xff, 0xff, 0xff)), new PointF(x, y), format);
             format.Dispose();
         }
     }
     catch (Exception exception1)
     {
         exception = exception1;
         this.message = exception.Message;
     }
     finally
     {
         graphics.Dispose();
     }
     if ((this.WaterMarkImagePath == null) || (this.WaterMarkImagePath.Trim() == string.Empty))
     {
         random = new Random();
         str3 = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + random.Next().ToString() + sExt;
         string str4 = HttpContext.Current.Server.MapPath("~/" + str);
         image.Save(str4 + @"\" + str3);
         helper.DeleteFile(HttpContext.Current.Server.MapPath("~/" + this.SourceImagePath));
         if (str.Substring(0, 1) == "/")
         {
             str = str.Substring(1, str.Length - 1);
         }
         this.filePath = str + "/" + str3;
         return true;
     }
     Image image2 = Image.FromFile(HttpContext.Current.Server.MapPath("~/" + this.WaterMarkImagePath));
     int num8 = image2.Width;
     int num9 = image2.Height;
     if ((width < num8) || (height < (num9 * 2)))
     {
         random = new Random();
         str3 = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + random.Next().ToString() + sExt;
         image.Save(HttpContext.Current.Server.MapPath("~/" + str) + @"\" + str3);
         helper.DeleteFile(HttpContext.Current.Server.MapPath("~/" + this.SourceImagePath));
         if (str.Substring(0, 1) == "/")
         {
             str = str.Substring(1, str.Length - 1);
         }
         this.filePath = str + "/" + str3;
         return true;
     }
     Bitmap bitmap2 = new Bitmap(image);
     image.Dispose();
     bitmap2.SetResolution(horizontalResolution, verticalResolution);
     Graphics graphics2 = Graphics.FromImage(bitmap2);
     ImageAttributes imageAttr = new ImageAttributes();
     ColorMap map = new ColorMap();
     map.OldColor = Color.FromArgb(0xff, 0, 0xff, 0);
     map.NewColor = Color.FromArgb(0, 0, 0, 0);
     imageAttr.SetRemapTable(new ColorMap[] { map }, ColorAdjustType.Bitmap);
     float[][] newColorMatrix = new float[5][];
     float[] numArray3 = new float[5];
     numArray3[0] = 1f;
     newColorMatrix[0] = numArray3;
     numArray3 = new float[5];
     numArray3[1] = 1f;
     newColorMatrix[1] = numArray3;
     numArray3 = new float[5];
     numArray3[2] = 1f;
     newColorMatrix[2] = numArray3;
     numArray3 = new float[5];
     numArray3[3] = this.ImageDeaphaneity;
     newColorMatrix[3] = numArray3;
     numArray3 = new float[5];
     numArray3[4] = 1f;
     newColorMatrix[4] = numArray3;
     imageAttr.SetColorMatrix(new ColorMatrix(newColorMatrix), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
     this.GetWaterMarkXY(out num10, out num11, width, height, num8, num9);
     graphics2.DrawImage(image2, new Rectangle(num10, num11, num8, num9), 0, 0, num8, num9, GraphicsUnit.Pixel, imageAttr);
     imageAttr.ClearColorMatrix();
     imageAttr.ClearRemapTable();
     image2.Dispose();
     graphics2.Dispose();
     try
     {
         random = new Random();
         str3 = "YXShop" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + random.Next().ToString() + sExt;
         bitmap2.Save(HttpContext.Current.Server.MapPath("~/" + str) + @"\" + str3);
         helper.DeleteFile(HttpContext.Current.Server.MapPath("~/" + this.SourceImagePath));
         if (str.Substring(0, 1) == "/")
         {
             str = str.Substring(1, str.Length - 1);
         }
         this.filePath = str + "/" + str3;
         return true;
     }
     catch (Exception exception2)
     {
         exception = exception2;
         this.message = exception.Message;
     }
     finally
     {
         bitmap2.Dispose();
     }
     return false;
 }
开发者ID:qq358292363,项目名称:showShop,代码行数:101,代码来源:UploadProcesedImages.cs

示例10: PostProcess

        private void PostProcess(ref Bitmap originalBitmap)
        {
            const float brightness = 1.0f;
            const float contrast = 2.0f;
            const float gamma = 0.8f;

            const float adjustedBrightness = brightness - 1.0f;

            float[][] colorMatrix =
            {
                new[] {contrast, 0, 0, 0, 0}, // red
                new[] {0, contrast, 0, 0, 0}, // green
                new[] {0, 0, contrast, 0, 0}, // blue
                new[] {0, 0, 0, 1.0f, 0}, // leave alpha as is
                new[] {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1}
            };

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

            var g = Graphics.FromImage(originalBitmap);
            g.DrawImage(
                originalBitmap,
                new Rectangle(0, 0, originalBitmap.Width, originalBitmap.Height),
                0,
                0,
                originalBitmap.Width,
                originalBitmap.Height,
                GraphicsUnit.Pixel,
                imageAttributes
            );
        }
开发者ID:Thunraz,项目名称:NLightened,代码行数:34,代码来源:MainWindowViewModel.cs

示例11: OnPaint

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            curval = (curval + nextval) / 2;
            curpos = (curpos + nextpos) / 2;
            cursel = (cursel + nextsel) / 2;
            curact = (curact + nextact) / 2;
            curanim = (curanim + nextanim) / 2f;
            if (curtick == maxcoltick) {
                Random r = new Random();

                nred = r.Next(255);
                ngreen = r.Next(255);
                nblue = r.Next(255);

                rred = (nred - cred) / maxcoltick;
                rgreen = (ngreen - cgreen) / maxcoltick;
                rblue = (nblue - cblue) / maxcoltick;

                curtick = 0;
            }
            curtick++;
            cred += rred;
            cgreen += rgreen;
            cblue += rblue;
            Rectangle rect = e.ClipRectangle;
            Bitmap b = new Bitmap(rect.Width, rect.Height);
            Graphics g = Graphics.FromImage(b);
            Rectangle q = rect;
            q.Inflate(-50, -50);
            Brush RandomColorBG = new SolidBrush(Color.FromArgb((int)Clamp(cred + 32, 0, 255), (int)Clamp(cgreen + 32, 0, 255), (int)Clamp(cblue + 32, 0, 255)));
            if(loaded)
                if(currentSong.HasArt)
                    e.Graphics.DrawImage(currentSong.art, q);
                else
                    e.Graphics.FillRectangle(colorMode == ColorMode.System ? new SolidBrush(SysColor) : (colorMode == ColorMode.Image ? new SolidBrush(SongColor) : RandomColorBG), q);
            Rectangle c = rect;
            if (playing) {
                float per = curval > 1 ? 1 : curval;
                c.Inflate(-50, -50);
                c.Inflate((int)(50 * per), (int)(50 * per));
            }
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
            Brush RandomColor = new SolidBrush(Color.FromArgb((int)cred, (int)cgreen, (int)cblue));
            g.FillEllipse(colorMode == ColorMode.System ? new SolidBrush(SysColor) : (colorMode == ColorMode.Image ? new SolidBrush(SongColor) : RandomColor), rect);
            g.FillPie(new SolidBrush(Color.FromArgb(128, (SongColor.R + SongColor.G + SongColor.B) / 3 < 32 && colorMode != ColorMode.Random ? Color.White : Color.Black)), c, 270f, curpos * 360f);

            StringFormat strfmt = new StringFormat();
            strfmt.Alignment = StringAlignment.Center;
            strfmt.LineAlignment = StringAlignment.Center;

            if (selecting) {
                if (loaded && !moving && !inCenter && currentSong.HasArt)
                    e.Graphics.FillRectangle(InnerBrush_Image, q);
                if (moving) {
                    if (mode == selectionModes.Position) {
                        g.FillPie(new SolidBrush(Color.FromArgb(128, Color.LightGray)), rect, 270f, cursel);
                    }
                    if (mode == selectionModes.Volume) {
                        g.FillPie(new SolidBrush(Color.FromArgb(128, Color.Black)), rect, 270f, curact);
                        g.FillPie(new SolidBrush(Color.FromArgb(64, Color.LightGray)), rect, 270f, cursel);
                    }
                    if (mode == selectionModes.Track) {
                        e.Graphics.FillRectangle(InnerBrush_Image, q);
                        nextact = NormalizeDegrees((((float)Math.Floor((cursel / 360f) * currentPlaylist.Songs.Count) / currentPlaylist.Songs.Count) * 360f) - 90f);
                        g.FillPie(new SolidBrush(Color.FromArgb(128, Color.Black)), rect, curact, (360f / currentPlaylist.Songs.Count));
                        e.Graphics.DrawString(currentPlaylist.Songs[(int)((nextsel / 360f) * currentPlaylist.Songs.Count)].title, SongInfoTitleFont, Brushes.Black, new RectangleF(q.Location, q.Size), strfmt);
                    }
                }
            }
            if (playlistActive)
                menucount = Labels.Length;
            else
                menucount = LabelsNoPlaylist.Length;
            if(curact > 0.5 && !moving){
                for (int i = 0; i < menucount; i++) {
                    g.FillPie(new SolidBrush(Color.FromArgb(64, Color.White)), rect, 270f + (i * curact), curact);
                    g.DrawPie(new Pen(Color.FromArgb(172, Color.White), 2), rect, 270f + (i * curact), curact);
                }
            }
            g.FillEllipse(Brushes.Lime, q);

            ImageAttributes ia = new ImageAttributes();
            ia.SetColorKey(Color.Green, Color.Lime);

            ColorMatrix matrix = new ColorMatrix();
            matrix.Matrix33 = curanim;
            ia.SetColorMatrix(matrix);
            if (loaded && (mouseInside || (!moving && mode != selectionModes.Track)) && (selecting ? inCenter : true)) {
                e.Graphics.FillEllipse(new SolidBrush(Color.FromArgb((int)(128 * curanim), Color.White)), q);
                e.Graphics.DrawImage(SongInformation, new Rectangle(50, 50, 200, 200), 0f, 0f, 200f, 200f, GraphicsUnit.Pixel, ia);
            }

            ia.ClearColorMatrix();

            e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImage(b, rect, rect.X, rect.Y, rect.Width, rect.Height, GraphicsUnit.Pixel, ia);

            if (loaded && selecting && !moving && !inCenter) {
                e.Graphics.DrawString(playlistActive ? Labels[(int)(nextsel / (360f / menucount))] : LabelsNoPlaylist[(int)(nextsel / (360f / menucount))], MenuSelectionFont, new SolidBrush(Color.FromArgb((int)(255 * curanim), Color.Black)), q, strfmt);
//.........这里部分代码省略.........
开发者ID:Magicpig55,项目名称:MMP,代码行数:101,代码来源:Form1.cs

示例12: ImageAdjust

        /// <summary>
        /// Adjust the brightness, contrast or gamma of the given image.
        /// </summary>
        /// <param name="originalImage">The original image.</param>
        /// <param name="brightness">The brightness multiplier (-1.99 to 1.99 fully white).</param>
        /// <param name="contrast">The contrast multiplier (2.0 would be twice the contrast).</param>
        /// <param name="gamma">The gamma multiplier (1.0 would no change in gamma).</param>
        /// <returns>A new adjusted image.</returns>
        private static Bitmap ImageAdjust( Bitmap originalImage, float brightness = 1.0f, float contrast = 1.0f, float gamma = 1.0f )
        {
            Bitmap adjustedImage = originalImage;

            float adjustedBrightness = brightness - 1.0f;
            // Matrix used to effect 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 },     // no change to alpha
                new float[] { adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1 }
            };

            var imageAttributes = new ImageAttributes();
            imageAttributes.ClearColorMatrix();
            imageAttributes.SetColorMatrix( new ColorMatrix( ptsArray ), ColorMatrixFlag.Default, ColorAdjustType.Bitmap );
            imageAttributes.SetGamma( gamma, ColorAdjustType.Bitmap );
            Graphics g = Graphics.FromImage( adjustedImage );
            g.DrawImage( originalImage, new Rectangle( 0, 0, adjustedImage.Width, adjustedImage.Height ),
                0, 0, originalImage.Width, originalImage.Height, GraphicsUnit.Pixel, imageAttributes );

            return adjustedImage;
        }
开发者ID:SparkDevNetwork,项目名称:Rock,代码行数:32,代码来源:RockFilters.cs

示例13: kontrastBerechnen

        //------------------------------------------------------------------------------------------------
        //Kontrast berechnen
        private void kontrastBerechnen()
        {
            Bitmap neueBitmap = new Bitmap(kontrastPicturebox.Image.Width, kontrastPicturebox.Image.Height);

            kontrastPicturebox.Image = null;
            GC.Collect();

            Debug.WriteLine("Verarbeiteter Wert: " + kontrastwert);

            float angepassteHelligkeit = (1.0f - kontrastwert) / 2.0f;

            float[][] meineMatrix ={
                    new float[] {kontrastwert, 0, 0, 0, 0},
                    new float[] {0, kontrastwert, 0, 0, 0},
                    new float[] {0, 0, kontrastwert, 0, 0},
                    new float[] {0, 0, 0, 1.0f, 0},
                    new float[] {angepassteHelligkeit,angepassteHelligkeit,angepassteHelligkeit, 0, 1}};

            ImageAttributes imageAttributes = new ImageAttributes();
            imageAttributes.ClearColorMatrix();
            imageAttributes.SetColorMatrix(new ColorMatrix(meineMatrix), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            Graphics g = Graphics.FromImage(neueBitmap);
            g.DrawImage(parent.getPictureBoxImage(), new Rectangle(0, 0, neueBitmap.Width, neueBitmap.Height), 0, 0, neueBitmap.Width, neueBitmap.Height,
                GraphicsUnit.Pixel, imageAttributes);
            kontrastPicturebox.Image = neueBitmap;
        }
开发者ID:Julius1990,项目名称:Prog3,代码行数:28,代码来源:kontrast.cs

示例14: CustomColorSettings

        public static BitmapImage CustomColorSettings(BitmapImage targetBitmap, float brightness = 1f, float contrast = 1.0f, float gamma = 1.0f)
        {
            if (brightness != 0) brightness /= 100;
            if (contrast != 0) contrast /= 100;
            if (gamma != 0) gamma /= 100;
            Bitmap originalImage = ConvertBitmapImageToBitmap(targetBitmap);
            Bitmap adjustedImage = new Bitmap(originalImage);
            float adjustedBrightness = brightness - 1.0f;
            float[][] ptsArray ={
            new float[] {contrast, 0, 0, 0, 0}, // Red
            new float[] {0, contrast, 0, 0, 0}, // Green
            new float[] {0, 0, contrast, 0, 0}, // Blue
            new float[] {0, 0, 0, 1.0f, 0},
            new float[] {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1}};

            var imageAttributes = new ImageAttributes();
            imageAttributes.ClearColorMatrix();
            imageAttributes.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            imageAttributes.SetGamma(gamma, ColorAdjustType.Bitmap);
            Graphics g = Graphics.FromImage(adjustedImage);
            g.DrawImage(adjustedImage, new Rectangle(0, 0, adjustedImage.Width, adjustedImage.Height)
                , 0, 0, originalImage.Width, originalImage.Height,
                GraphicsUnit.Pixel, imageAttributes);
            BitmapImage outputBitmapImage = ConvertBitmapToBitmapImage(adjustedImage);
            return outputBitmapImage;
        }
开发者ID:Wayfind3r,项目名称:WPF-Picture-Editor,代码行数:26,代码来源:ImageProcessing.cs

示例15: helligkeitberechnen

        //------------------------------------------------------------------------------------------------
        //Helligkeit berechnen
        private void helligkeitberechnen()
        {
            Bitmap neueBitmap = new Bitmap(helligkeitPicturebox.Image.Width, helligkeitPicturebox.Image.Height);

            //Vorigen Bearbeitungsschritt löschen
            helligkeitPicturebox.Image = null;
            GC.Collect();

            float[][] meineMatrix ={
                    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.0f, 0},
                    new float[] {helligkeitParameter,helligkeitParameter,helligkeitParameter, 0, 1}};

            ImageAttributes imageAttributes = new ImageAttributes();
            imageAttributes.ClearColorMatrix();
            imageAttributes.SetColorMatrix(new ColorMatrix(meineMatrix), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            Graphics g = Graphics.FromImage(neueBitmap);
            g.DrawImage(parent.getPictureBoxImage(), new Rectangle(0, 0, neueBitmap.Width, neueBitmap.Height), 0, 0, neueBitmap.Width, neueBitmap.Height,
                GraphicsUnit.Pixel, imageAttributes);
            helligkeitPicturebox.Image = neueBitmap;
        }
开发者ID:Julius1990,项目名称:Prog3,代码行数:25,代码来源:helligkeit.cs


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