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

SetGamma() public method

public SetGamma ( float gamma ) : void
gamma float
return void
		public void SetGamma(float gamma)
		{
			SetGamma(gamma, ColorAdjustType.Default);
		}

Same methods

ImageAttributes::SetGamma ( float gamma, ColorAdjustType type ) : void

Usage Example

示例#1
0
        private void pictureBox11_Click(object sender, EventArgs e)
        {
            undo.Push(pictureBox2.Image);
            imi1   = pictureBox2.Image;
            ImUndo = imi1;
            Bitmap originalImage = (Bitmap)pictureBox2.Image;
            Bitmap adjustedImage = (Bitmap)pictureBox2.Image;
            float  brightness    = 1.0f;                                   // no change in brightness
            float  contrast      = Convert.ToSingle(numericUpDown1.Value); // twice the contrast
            float  gamma         = 1.0f;                                   // no change in gamma

            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 }
            };
            System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.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);
            pictureBox2.Image = adjustedImage;
            sandi             = adjustedImage;
        }
All Usage Examples Of System.Drawing.Imaging.ImageAttributes::SetGamma