1: public static Bitmap Dilate(Bitmap Image, int Size)
2: { 3: System.Drawing.Bitmap TempBitmap = Image;
4: System.Drawing.Bitmap NewBitmap = new System.Drawing.Bitmap(TempBitmap.Width, TempBitmap.Height);
5: System.Drawing.Graphics NewGraphics = System.Drawing.Graphics.FromImage(NewBitmap);
6: NewGraphics.DrawImage(TempBitmap, new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), new System.Drawing.Rectangle(0, 0, TempBitmap.Width, TempBitmap.Height), System.Drawing.GraphicsUnit.Pixel);
7: NewGraphics.Dispose();
8: Random TempRandom = new Random();
9: int ApetureMin = -(Size / 2);
10: int ApetureMax = (Size / 2);
11: for (int x = 0; x < NewBitmap.Width; ++x)
12: { 13: for (int y = 0; y < NewBitmap.Height; ++y)
14: { 15: int RValue = 0;
16: int GValue = 0;
17: int BValue = 0;
18: for (int x2 = ApetureMin; x2 < ApetureMax; ++x2)
19: { 20: int TempX = x + x2;
21: if (TempX >= 0 && TempX < NewBitmap.Width)
22: { 23: for (int y2 = ApetureMin; y2 < ApetureMax; ++y2)
24: { 25: int TempY = y + y2;
26: if (TempY >= 0 && TempY < NewBitmap.Height)
27: { 28: Color TempColor = TempBitmap.GetPixel(TempX, TempY);
29: if (TempColor.R > RValue)
30: RValue = TempColor.R;
31: if (TempColor.G > GValue)
32: GValue = TempColor.G;
33: if (TempColor.B > BValue)
34: BValue = TempColor.B;
35: }
36: }
37: }
38: }
39: Color TempPixel = Color.FromArgb(RValue, GValue, BValue);
40: NewBitmap.SetPixel(x, y, TempPixel);
41: }
42: }
43: return NewBitmap;
44: }