? ? ? ? ? ? ? if (g < 0) g = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (g > 255) g = 255;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (b < 0) b = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (b > 255) b = 255;
? ? ? ? ? ? ? ? ? ? ? ? ? ? int off2 = (j * Width + i) * 4;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[off2 + 0] = (byte)r;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[off2 + 1] = (byte)g;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[off2 + 2] = (byte)b;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? bitmap.UnlockBits(newData);
? ? ? ? ? ? ? ? ? ? MyBitmap.UnlockBits(oldData);
? ? ? ? ? ? ? ? ? ? this.pbshowbox.Image = bitmap;
? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("请先打开一张图片!");
? ? ? ? ? ? }
? ? ? ? }
三、锐化
突出显示颜色值大的像素点。

///
? ? ? ? /// 锐化实现方法,显示数值最大像素点
? ? ? ? ///
? ? ? ? void Image_Sharpen()
? ? ? ? {
? ? ? ? ? ? if (this.pbshowbox.Image != null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int Height = this.pbshowbox.Image.Height;
? ? ? ? ? ? ? ? int Width = this.pbshowbox.Image.Width;
? ? ? ? ? ? ? ? Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppRgb);
? ? ? ? ? ? ? ? Bitmap MyBitmap = (Bitmap)this.pbshowbox.Image;
? ? ? ? ? ? ? ? BitmapData oldData = MyBitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
? ? ? ? ? ? ? ? BitmapData newData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppRgb);
? ? ? ? ? ? ? ? unsafe
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? byte* pin = (byte*)(oldData.Scan0.ToPointer());
? ? ? ? ? ? ? ? ? ? byte* pout = (byte*)(newData.Scan0.ToPointer());
? ? ? ? ? ? ? ? ? ? //拉普拉斯模板
? ? ? ? ? ? ? ? ? ? int[] Laplacian = { -1, -1, -1, -1, 9, -1, -1, -1, -1 };
? ? ? ? ? ? ? ? ? ? for (int i = 1; i < Width - 1; i++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? for (int j = 1; j < Height - 1; j++)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? int r = 0, g = 0, b = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? int Index = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? for (int col = -1; col <= 1; col++)
? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for (int row = -1; row <= 1; row++)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int off = ((j + row) * (Width) + (i + col)) * 4;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? r += pin[off + 0] * Laplacian[Index];
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? g += pin[off + 1] * Laplacian[Index];
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? b += pin[off + 2] * Laplacian[Index];
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Index++;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (r < 0) r = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (r > 255) r = 255;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (g < 0) g = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (g > 255) g = 255;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (b < 0) b = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (b > 255) b = 255;
? ? ? ? ? ? ? ? ? ? ? ? ? ? int off2 = (j * Width + i) * 4;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[off2 + 0] = (byte)r;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[off2 + 1] = (byte)g;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[off2 + 2] = (byte)b;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? bitmap.UnlockBits(newData);
? ? ? ? ? ? ? ? ? ? MyBitmap.UnlockBits(oldData);
? ? ? ? ? ? ? ? ? ? this.pbshowbox.Image = bitmap;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("请先打开一张图片!");
? ? ? ? ? ? }
? ? ? ? }
四、浮雕
对图像像素点的像素值分别与相邻像素点的像素值相减后加上128,?然后将其作为新的像素点的值。

///
? ? ? ? /// 浮雕实现方法
? ? ? ? ///
? ? ? ? void Image_Relief()
? ? ? ? {
? ? ? ? ? ? if (this.pbshowbox.Image != null)
? ? ? ? ? ? {
? ? ? ? ? ? ?
? ? ? ? ? ? ? ? int Height = this.pbshowbox.Image.Height;
? ? ? ? ? ? ? ? int Width = this.pbshowbox.Image.Width;
? ? ? ? ? ? ? ? Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
? ? ? ? ? ? ? ? Bitmap MyBitmap = (Bitmap)this.pbshowbox.Image;
? ? ? ? ? ? ? ? BitmapData oldData = MyBitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
? ? ? ? ? ? ? ? BitmapData newData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
? ? ? ? ? ? ? ? unsafe
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? byte* pin_1 = (byte*)(oldData.Scan0.ToPointer());
? ? ? ? ? ? ? ? ? ? byte* pin_2 = pin_1 + (oldData.Stride);? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? byte* pout = (byte*)(newData.