分析是一门科学,设计是一门艺术

每天进步一点点

导航

C#图片处理之:Gamma校正

 gamma值是用曲线表示的,这是一种人的眼睛对光的一种感应曲线,其中包括了物理量、身理感官及心理的感知度。

 1        /// <summary>
 2        /// Gamma校正
 3        /// </summary>
 4        /// <param name="bmp">输入Bitmap</param>
 5        /// <param name="val">[0 <-明- 1 -暗-> 2]</param>
 6        /// <returns>输出Bitmap</returns>

 7        public static Bitmap KiGamma(Bitmap bmp, float val)
 8        {
 9            if (bmp == null)
10            {
11                return null;
12            }

13
14            // 1表示无变化,就不做
15            if (val == 1.0000freturn bmp;
16
17            try
18            {
19                 Bitmap b = new Bitmap(bmp.Width, bmp.Height);
20                Graphics g = Graphics.FromImage(b);
21                ImageAttributes attr = new ImageAttributes();
22
23                attr.SetGamma(val, ColorAdjustType.Bitmap);
24                g.DrawImage(bmp, new Rectangle(00, bmp.Width, bmp.Height), 00, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attr);
25                g.Dispose();
26                return b;
27            }

28            catch
29            {
30                return null;
31            }

32        }

posted on 2008-03-10 13:36  布衣(Dream2008)  阅读(550)  评论(0编辑  收藏  举报