比較GDI+使用的GetPixel/SetPixel,讓你立馬感到這個世界多麼美妙
再來一個中值濾波的操作
1 /// <summary>
2 /// 中值濾波
3 /// </summary>
4 /// <param name="dgGrayValue"></param>
5 public void MedianFilter(int dgGrayValue)
6 {
7 // 100M 雙線空間 + 50M數據庫 28元/年
8 // 1G 雙線空間 + 200M數據庫 100元/年
9 // QQ:70975363
10 byte s;
11 byte[] p = new byte[9];
12 int i, j;
13 int x, y;
14 int Stride;
15 unsafe
16 {
17 byte* point = (byte*)this.ImageData.Scan0;
18 Stride = this.ImageData.Stride;
19 point = point + 3 + this.ImageData.Stride;
20 for (i = 0; i < this.ImageData.Height - 1; i++)
21 {
22 for (j = 0; j < this.ImageData.Width - 1; j++)
23 {
24 p[0] = *(point - Stride - 1);
25 p[1] = *(point - Stride + 2);
26 p[2] = *(point - Stride + 5);
27 p[3] = *(point - 1);
28 p[4] = *(point + 2);
29 p[5] = *(point + 5);
30 p[6] = *(point + Stride - 1);
31 p[7] = *(point + Stride + 2);
32 p[8] = *(point + Stride + 5);
33 for (x = 0; x < 5; x++)
34 {
35 for (y = x + 1; y < 9; y++)
36 {
37 if (p[x] > p[y])
38 {
39 s = p[x];
40 p[x] = p[y];
41 p[y] = s;
42 }
43 }
44 }
45 *point = p[4];
46 *(point - 1) = p[4];
47 *(point - 2) = p[4];
48 point += 3;
49
50 }
51 point += Stride - this.ImageData.Width * 3;
52 }
53 }
54 }
55