The image is embossed. The pixel value of the image is reduced by 128 after the pixel value of the adjacent pixel is subtracted, and then used as the value of the new pixel.
The image is displayed with relief effect. The value of each pixel is obtained through the GetPixel method, and the pixel value is set through SetPixel. The Code is as follows:
Private void button#click (object sender, EventArgs e)
{
// Display the image with relief effect
Try
{
Int Height = this. pictureBox1.Image. Height;
Int Width = this. pictureBox1.Image. Width;
Bitmap newBitmap = new Bitmap (Width, Height );
Bitmap oldBitmap = (Bitmap) this. pictureBox1.Image;
Color pixel1, pixel2;
For (int x = 0; x <Width-1; x ++)
{
For (int y = 0; y <Height-1; y ++)
{
Int r = 0, g = 0, B = 0;
Pixel1 = oldBitmap. GetPixel (x, y );
Pixel2 = oldBitmap. GetPixel (x + 1, y + 1 );
R = Math. Abs (pixel1.R-pixel2.R + 128 );
G = Math. Abs (pixel1.G-pixel2.G + 128 );
B = Math. Abs (pixel1. B-pixel2. B + 128 );
If (r> 255)
R = 255;
If (r <0)
R = 0;
If (g> 255)
G = 255;
If (g <0)
G = 0;
If (B> 255)
B = 255;
If (B <0)
B = 0;
NewBitmap. SetPixel (x, y, Color. FromArgb (r, g, B ));
}
}
This. pictureBox1.Image = newBitmap;
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message, "Message prompt", MessageBoxButtons. OK, MessageBoxIcon. Information );
}
}