请问怎么样编写代码实现图片的锐化效果?
private void 锐化ToolStripMenuItem_Click(object sender, EventArgs e){
int Height = this.pictureBox1.Image.Height;
int Width = this.pictureBox1.Image.Width;
Bitmap bitmap = new Bitmap(Height, Width);
Bitmap mybitmap = (Bitmap)this.pictureBox1.Image;
Color pixel;
int[] Laplacian ={ -1, -1, -1, -1, 9, -1, -1, -1, -1 };
for(int x = 1; x < Width - 1; x++)
for (int y = 1; y < Height - 1; y++)
{
int r = 0, g = 0, b = 0;
int Index = 0;
// int a = 0;
for(int col = -1;col <= 1 ; col++)
for (int row = -1; row <= 1; row++)
{
pixel = mybitmap.GetPixel(x + row, y + col);
r += pixel.R * Laplacian[Index];
g += pixel.G * Laplacian[Index];
b += pixel.B * Laplacian[Index];
Index++;
}
r = r > 255 ? 255 : r;
r = r < 0 ? 0 : r;
g = g > 255 ? 255 : g;
g = g < 0 ? 0 : g;
b = b > 255 ? 255 : b;
b = b < 0 ? 0 : b;
bitmap.SetPixel(x , y , Color.FromArgb(r, g, b) ); //这一句总是提示出错了
}
this.pictureBox1.Image = bitmap;
}