Идея состоит в том, чтобы сравнить яркость текущего пикселя со смещенным пикселем (смещением на 5 пикселей) и вычислить новое значение оттенков серого.
Вот мой код:
Код: Выделить всё
public static void ApplyReliefEffect(Form form)
{
if (ImageStorage.bitmap != null)
{
int brightness;
int brightness1;
int brightness2;
Bitmap sourceBitmap = new Bitmap(ImageStorage.bitmap);
Bitmap offsetBitmap = new Bitmap(ImageStorage.bitmap);
Color currentPixel;
Color offsetPixel;
Graphics graphics = form.CreateGraphics();
for (int x = 5; x < sourceBitmap.Width; x++)
{
for (int y = 5; y < sourceBitmap.Height; y++)
{
currentPixel = sourceBitmap.GetPixel(x, y);
offsetPixel = offsetBitmap.GetPixel(x - 5, y - 5);
brightness1 = CalculateBrightness(currentPixel);
brightness2 = CalculateBrightness(offsetPixel);
brightness = 150 + (brightness2 - brightness1);
if (brightness < 0)
{
brightness = 0;
}
else if (brightness > 255)
{
brightness = 255;
}
sourceBitmap.SetPixel(x, y, Color.FromArgb(brightness, brightness, brightness));
}
}
graphics.DrawImage(sourceBitmap, 25, 50);
graphics.Dispose();
}
}