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.0000f) return 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(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attr);
25
g.Dispose();
26
return b;
27
}
28
catch
29
{
30
return null;
31
}
32
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32
