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


C# ImageAttributes.SetGamma方法代码示例

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


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

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

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

示例4: Draw

 public override void Draw(Graphics g, int x, int y, Size sizTile, TemplateDoc tmpd, LayerType layer, bool fSelected)
 {
     if (layer == LayerType.Scenery) {
         Bitmap[] abm = m_gimg.GetBitmapSides(sizTile);
         Bitmap bm = abm[0];
         if (fSelected) {
             Rectangle rcDst = new Rectangle(x, y, bm.Width, bm.Height);
             ImageAttributes attr = new ImageAttributes();
             attr.SetGamma(0.5f);
             g.DrawImage(bm, rcDst, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel, attr);
         } else {
             g.DrawImage(bm, x, y);
         }
     }
 }
开发者ID:RusselRains,项目名称:hostile-takeover,代码行数:15,代码来源:scenery.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: ChangeGamma

        public static Image ChangeGamma(Image img, float gamma)
        {
            Bitmap bmp = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppArgb);

            gamma = gamma / 100 + 1;
            gamma = gamma.Between(0.1f, 10.0f);

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

            return bmp;
        }
开发者ID:dmitriydel,项目名称:sharexmod,代码行数:18,代码来源:ColorMatrixMgr.cs

示例7: AdjustImage

        /// <summary>
        /// Метод изменения яркости и контрастности изображения
        /// </summary>
        /// <param name="image">Изображение</param>
        /// <param name="brightness">Яркость</param>
        /// <param name="gamma">Гамма</param>
        /// <param name="cRed">Контраст красного</param>
        /// <param name="cGreen">Контраст зеленого</param>
        /// <param name="cBlue">Контраст синего</param>
        /// <param name="cAlpha">Прозрачность</param>
        /// <returns>Новое изображение</returns>
        public static Bitmap AdjustImage(Image image, float brightness = 1.0f, float gamma = 1.0f, float cRed = 1.0f, float cGreen = 1.0f, float cBlue = 1.0f, float cAlpha = 1.0f)
        {
            brightness -= 1.0f; // Значение яркости указывается в виде дельты, то есть 0 - нет изменений, 0.5 - увеличить на 50%, -0.5 - уменьшить на 50% и т.д.
            float[][] matrix =
            {
                new float[] { cRed, 0, 0, 0, 0 },   // Контраст красного
                new float[] { 0, cGreen, 0, 0, 0 }, // Контраст зеленого
                new float[] { 0, 0, cBlue, 0, 0 },  // Контраст синего
                new float[] { 0, 0, 0, cAlpha, 0 }, // Контраст альфы
                new float[] { brightness, brightness, brightness, 0, 1 } // Яркость
            };

            ImageAttributes atts = new ImageAttributes();
            atts.SetColorMatrix(new ColorMatrix(matrix), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            atts.SetGamma(gamma, ColorAdjustType.Bitmap);

            Bitmap newImage = new Bitmap(image.Width, image.Height);
            using (var gfx = Graphics.FromImage(newImage))
                gfx.DrawImage(image, new Rectangle(0, 0, newImage.Width, newImage.Height), 0, 0, newImage.Width, newImage.Height, GraphicsUnit.Pixel, atts);
            return newImage;
        }
开发者ID:Black-millenium,项目名称:Median-Filtering,代码行数:32,代码来源:ColorProcessing.cs

示例8: Form1_KeyDown

 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     switch (e.KeyCode)
     {
         // 리셋
         case Keys.Space:
             Attr = new ImageAttributes();
             Src = Image.FromFile("오솔길.jpg");
             Threshold = 0.5f;
             Gamma = 1.0f;
             Bright = 0.0f;
             break;
         // 시계 방향 회전
         case Keys.Right:
             Src.RotateFlip(RotateFlipType.Rotate90FlipNone);
             break;
         // 반시계 방향 회전
         case Keys.Left:
             Src.RotateFlip(RotateFlipType.Rotate270FlipNone);
             break;
         // 수평 뒤집기
         case Keys.Up:
             Src.RotateFlip(RotateFlipType.RotateNoneFlipX);
             break;
         // 수직 뒤집기
         case Keys.Down:
             Src.RotateFlip(RotateFlipType.RotateNoneFlipY);
             break;
         // 스레시 홀드 증감
         case Keys.Q:
             if (Threshold < 1) Threshold += 0.1f;
             Attr.SetThreshold(Threshold);
             break;
         case Keys.W:
             if (Threshold > 0) Threshold -= 0.1f;
             Attr.SetThreshold(Threshold);
             break;
         // 감마 증감
         case Keys.E:
             if (Gamma < 5.0) Gamma += 0.1f;
             Attr.SetGamma(Gamma);
             break;
         case Keys.R:
             if (Gamma > 0.1) Gamma -= 0.1f;
             Attr.SetGamma(Gamma);
             break;
         // 밝게
         case Keys.D1:
             if (Bright < 1.0f) Bright += 0.1f;
             float[][] M1 = {
                 new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
                 new float[] {Bright, Bright, Bright, 0.0f, 1.0f},
             };
             ColorMatrix Mat1 = new ColorMatrix(M1);
             Attr.SetColorMatrix(Mat1);
             break;
         // 어둡게
         case Keys.D2:
             if (Bright > -1.0f) Bright -= 0.1f;
             float[][] M2 = {
                 new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
                 new float[] {Bright, Bright, Bright, 0.0f, 1.0f},
             };
             ColorMatrix Mat2 = new ColorMatrix(M2);
             Attr.SetColorMatrix(Mat2);
             break;
         // 반전
         case Keys.D3:
             float[][] M3 = {
                 new float[] {-1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, -1.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, -1.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
                 new float[] {1.0f, 1.0f, 1.0f, 0.0f, 1.0f},
             };
             ColorMatrix Mat3 = new ColorMatrix(M3);
             Attr.SetColorMatrix(Mat3);
             break;
         // 그레이 스케일
         case Keys.D4:
             float[][] M4 = {
                 new float[] {0.299f, 0.299f, 0.299f, 0.0f, 0.0f},
                 new float[] {0.587f, 0.587f, 0.587f, 0.0f, 0.0f},
                 new float[] {0.114f, 0.114f, 0.114f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
             };
             ColorMatrix Mat4 = new ColorMatrix(M4);
             Attr.SetColorMatrix(Mat4);
             break;
         case Keys.D5:
             ColorMap[] Map = new ColorMap[1];
             Map[0] = new ColorMap();
             Map[0].OldColor = Color.White;
//.........这里部分代码省略.........
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:101,代码来源:Form1.cs

示例9: OnPaint

        protected override void OnPaint(PaintEventArgs e)
        {
            if (_imageSlot != null)
            {
                var attr = new System.Drawing.Imaging.ImageAttributes();
                int top = Top;
                int bottom = Top + Height;
                int left = Left;
                int right = Left + Width;

                attr.SetGamma(gamma);

                int squarish = Math.Max(_imageSlot.Width, _imageSlot.Height);
                squarish = (int)(squarish * 1.25);

                if (renderBack)
                    e.Graphics.DrawImage(_imageBack,
                        new Rectangle((Width / 2) - (squarish / 2), (Height / 2) - (squarish / 2), squarish, squarish),
                        new Rectangle(0, 0, _imageBack.Width, _imageBack.Height), GraphicsUnit.Pixel);
                    //e.Graphics.DrawImage(_imageBack, (Width / 2) - (_imageBack.Width / 2), (Height / 2) - (_imageBack.Height / 2));

                //e.Graphics.DrawImage(_image, (Width / 2) - (_image.Width / 2), (Height / 2) - (_image.Height / 2));

                //Point[] dest = new Point[]{ new Point(top, left), new Point(top, right), new Point(bottom, right)};
                e.Graphics.DrawImage(_imageSlot,
                    new Rectangle((Width / 2) - (_imageSlot.Width / 2), (Height / 2) - (_imageSlot.Height / 2), _imageSlot.Width, _imageSlot.Height),
                    0, 0, _imageSlot.Width, _imageSlot.Height,
                    GraphicsUnit.Pixel, attr);

                int smallish = (int)(squarish * 0.5);

                if (coolness != 0)
                {
                    float[] colour = new float[] { 0, 0.6f, 0, 0, 1 };

                    if (coolness == 2)
                        colour = new float[] { 0.1f, 0.2f, 0.8f, 0, 1 };
                    else if (coolness == 3)
                        colour = new float[] { 0.8f, 0, 0.8f, 0, 1 };
                    else if (coolness == 4)
                        colour = new float[] { 0.5f, 0.1f, 0, 0, 1 };

                    float[][] ptsArray =
                    {
                    new float[] {0.7f, 0, 0, 0, 0},
                    new float[] {0, 0.7f, 0, 0, 0},
                    new float[] {0, 0, 0.7f, 0, 0},
                    new float[] {0, 0, 0, 1, 0}, colour
                    };
                    ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
                    attr.SetColorMatrix(clrMatrix,
                    ColorMatrixFlag.Default,
                    ColorAdjustType.Default);
                }

                if (_imageSet != null)
                {
                    e.Graphics.DrawImage(_imageSet,
                        new Rectangle((Width / 2) - (smallish / 2), (Height / 2) - (smallish / 2), smallish, smallish),
                        0, 0, _imageSet.Width, _imageSet.Height,
                        GraphicsUnit.Pixel, attr);
                }

                // for int grade draw star
                if (renderStars)
                {
                    for (int i = 0; i < grade; i++)
                    {
                        e.Graphics.DrawImage(_imageStars,
                            new Rectangle((Width / 2) - (squarish / 2) + 2 + (8 + 6 / grade) * i, (Height / 2) - (squarish / 2) + 3, 13, 13),
                            new Rectangle(0, 0, _imageStars.Width, _imageStars.Height),
                            GraphicsUnit.Pixel);
                    }
                }

            }
        }
开发者ID:Riversilk,项目名称:RuneManager,代码行数:77,代码来源:RuneControl.cs

示例10: GenerateImages

        /// <summary>
        /// 画像データ生成
        /// </summary>
        /// <param name="width">出力幅</param>
        /// <param name="height">出力高さ</param>
        /// <param name="src">元画像データ出力バッファ</param>
        /// <returns>結果画像</returns>
        public Image GenerateImages(int width, int height, out Image src)
        {
            src = Image.FromFile(Path);
            switch (Rotate)
            {
                case PageRotate.Rotate0:
                    src.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                    break;
                case PageRotate.Rotate90:
                    src.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;
                case PageRotate.Rotate180:
                    src.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    break;
                case PageRotate.Rotate270:
                    src.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    break;
            }
            if (Format < 0)
            {
                switch (src.PixelFormat)
                {
                    default:
                        // フルカラー
                        Format = Page.PageFormat.FullColor;
                        break;
                    case PixelFormat.Format8bppIndexed:
                        // 8bitグレイスケール
                        Format = Page.PageFormat.Gray8bit;
                        break;
                    case PixelFormat.Format16bppGrayScale:
                        // 8bitグレイスケールにしちゃう
                        Format = Page.PageFormat.Gray8bit;
                        break;
                    case PixelFormat.Format4bppIndexed:
                        // 4bitグレイスケール
                        Format = Page.PageFormat.Gray4bit;
                        break;
                    case PixelFormat.Format1bppIndexed:
                        // 白黒
                        Format = Page.PageFormat.Mono;
                        break;
                }
            }

            int srcWidth = src.Width * (100 - clipLeft - (100 - clipRight)) / 100;
            int srcHeight = src.Height * (100 - clipTop - (100 - clipBottom)) / 100;
            if (srcWidth / (double)width < srcHeight / (double)height)
            {
                double d = srcHeight / (double)height;
                width = (int)(srcWidth / d);
            }
            else
            {
                double d = srcWidth / (double)width;
                height = (int)(srcHeight / d);
            }

            if (width <= 0 || height <= 0)
            {
                return null;
            }

            // コントラスト指定
            ImageAttributes attr = new ImageAttributes();
            float contrast = this.contrast + 1.0f;
            float[][] array = { 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, 0},    // alpha
                                new float[] {(1.0f - contrast) * 0.5f, (1.0f - contrast) * 0.5f, (1.0f - contrast) * 0.5f, 0, 1}     // transform
                              };
            attr.SetColorMatrix(new ColorMatrix(array), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            attr.SetGamma(1.0f, ColorAdjustType.Bitmap);

            // ビットマップ生成
            Image target = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(target);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.DrawImage(src, new Rectangle(0, 0, width, height), src.Width * clipLeft / 100, src.Height * clipTop / 100, srcWidth, srcHeight, GraphicsUnit.Pixel, attr);
            g.Dispose();

            if (Format > Page.PageFormat.FullColor)
            {
                // 太字化はこの段階で反映
                target = ConvertFormat(Boldize((Bitmap)target, this.bold), Format);
            }

            return target;
        }
开发者ID:unak,项目名称:EPubMaker2,代码行数:97,代码来源:Page.cs

示例11: GammaBmp

        private static Bitmap GammaBmp( Bitmap bmpBlend, float gamma)
        {
            Bitmap bmpNew = new Bitmap(bmpBlend.Width, bmpBlend.Height);
            Graphics g = Graphics.FromImage(bmpNew);

            ImageAttributes attr = new ImageAttributes();
            attr.SetGamma((float)(1.0/gamma));

            g.DrawImage(bmpBlend, new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), 0, 0, bmpBlend.Width, bmpBlend.Width, GraphicsUnit.Pixel, attr);

            g.Flush();
            g.Dispose();
            bmpBlend.Dispose();
            return bmpNew;
        }
开发者ID:ngonzalezromero,项目名称:wwt-windows-client,代码行数:15,代码来源:WarpMapper.cs

示例12: apply

        public Image apply(Image img)
        {
            //Program.dbg(System.Threading.Thread.CurrentThread.ManagedThreadId + "");
            //Image im = (Image)img.Clone();
            Image im = img;
            if (rotate == 1) im.RotateFlip(RotateFlipType.Rotate90FlipNone);
            if (rotate == 2) im.RotateFlip(RotateFlipType.Rotate180FlipNone);
            if (rotate == 3) im.RotateFlip(RotateFlipType.Rotate270FlipNone);

            if (brigh != DEFAULT_BRIGH ||
                contr != DEFAULT_CONTR ||
                gamma != DEFAULT_GAMMA)
            {
                using (Graphics g = Graphics.FromImage(im))
                {
                    float b = _brigh;
                    float c = _contr;
                    ImageAttributes derp = new ImageAttributes();
                    derp.SetColorMatrix(new ColorMatrix(new float[][]{
                            new float[]{c, 0, 0, 0, 0},
                            new float[]{0, c, 0, 0, 0},
                            new float[]{0, 0, c, 0, 0},
                            new float[]{0, 0, 0, 1, 0},
                            new float[]{b, b, b, 0, 1}}));
                    derp.SetGamma(_gamma);
                    g.DrawImage(img, new Rectangle(Point.Empty, img.Size),
                        0, 0, img.Width, img.Height, GraphicsUnit.Pixel, derp);
                }
            }
            //Program.dbg("Applied filters");
            return im; // == null? (Image)img.Clone() : im;
        }
开发者ID:JacekWojciechowski,项目名称:ImageGlass,代码行数:32,代码来源:ImgFilter.cs

示例13: SetGamma

        /// <summary>
        /// Redraw image into itself using the given gamma correction. 0.1 to 5.0 are allowed. 2.0 produces no change
        /// </summary>
        /// <param name="source"></param>
        /// <param name="luminance"></param>
        public static void SetGamma(Image source, float _gamma)
        {
            // clamp to range

            float gamma = Math.Max(0.1f, Math.Min(_gamma, 5.0f));

            // create image attributes

            ImageAttributes ia = new ImageAttributes();

            ia.SetGamma(gamma);

            // get a graphics for source image

            Graphics g = Graphics.FromImage(source);

            // set compositing mode to copy over

            g.CompositingMode = CompositingMode.SourceCopy;

            // turn off aliasing etc

            g.InterpolationMode = InterpolationMode.NearestNeighbor;

            g.SmoothingMode = SmoothingMode.None;

            // create destination rectangle

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

            // paint into self

            g.DrawImage(source, d, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, ia);

            // cleanup

            ia.Dispose();

            g.Dispose();
        }
开发者ID:duncanmeech,项目名称:RedEye,代码行数:45,代码来源:ImageUtility.cs

示例14: DrawBrightImage

 /// <summary>Adjust gamma of an image [not used]</summary>
 private void DrawBrightImage(Graphics g, Image img, Rectangle bounds, float gamma)
 {
     try
     {
         using (Bitmap buttonImage = new Bitmap(img))
         {
             using (ImageAttributes imageAttr = new ImageAttributes())
             {
                 if (gamma > .9f)
                     gamma = .9f;
                 if (gamma < .2f)
                     gamma = .2f;
                 // raise gamma
                 imageAttr.SetGamma(gamma);
                 g.DrawImage(buttonImage,
                     bounds,
                     0, 0,
                     buttonImage.Width,
                     buttonImage.Height,
                     GraphicsUnit.Pixel,
                     imageAttr);
             }
         }
     }
     catch { }
 }
开发者ID:Sektorka,项目名称:MariaRadio,代码行数:27,代码来源:Slider.cs

示例15: ApplyHeatValueToImage

        /// <summary>
        /// Change the intensity of the image
        /// </summary>
        /// <param name="image">The dot image</param>
        /// <param name="weight">The weight to apply</param>
        /// <returns>The weighted image</returns>
        private static Bitmap ApplyHeatValueToImage(Bitmap image, float weight)
        {
            var tempImage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb);

            using (IGraphics g = Graphics.FromImage(tempImage).G())
            {
                //I want to make the color more intense (White/bright)
                if (weight < 0.02f) weight = 0.02f;
                weight *= 5f;
                if (weight > 5f) weight = 5f;

                // Create ImageAttributes
                var ia = new ImageAttributes();

                //Gamma values range from 0.1 to 5.0 (normally 0.1 to 2.2), with 0.1 being the brightest and 5.0 the darkest.
                //Convert the 100% to a range of 0.1-5 by multiplying it by 5
                ia.SetGamma(weight, ColorAdjustType.Bitmap);

                // Draw Image with the attributes
                g.DrawImage(image,
                    0, 0, image.Width, image.Height,
                    0, 0, image.Width, image.Height,
                    GraphicsUnitType.Pixel, ia);
            }
            //New dot with a different intensity
            return tempImage;
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:33,代码来源:HeatLayer.cs


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