C# 重绘设置Image亮度

来源:互联网 发布:数据中心网络架构 编辑:程序博客网 时间:2024/06/05 19:39


value : -1 - 1

 public Bitmap SetImageBrightness(Image img,float value)        {            //float value = -0.3f;// -25 * 0.01f;            float[][] colorMatrixElements = {            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[] {value,value,value,0,1}};            Bitmap bmLast = new Bitmap(Convert.ToInt32(img.Width), Convert.ToInt32(img.Height));            using (ImageAttributes imageAttributes = new ImageAttributes())            {                ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);                imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);                using (Graphics gs = Graphics.FromImage(bmLast))                {                    gs.DrawImage(img, new Rectangle(0, 0, bmLast.Width, bmLast.Height), 0, 0, bmLast.Width, bmLast.Height, GraphicsUnit.Pixel, imageAttributes);                }            }            return bmLast;        }


原创粉丝点击