/// <summary>
/// 浮雕效果图
/// </summary>
/// <param name="SImage">原图</param>
/// <param name="p">80左右</param>
/// <returns></returns>
public static Bitmap Relief(Bitmap SImage, int p)
{
int Height = SImage.Height;
int Width = SImage.Width;
Bitmap bitmap = new Bitmap(Width, Height);
Bitmap MyBitmap = (Bitmap)SImage;
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 = MyBitmap.GetPixel(x, y);
pixel2 = MyBitmap.GetPixel(x + 1, y + 1);
r = pixel1.R - pixel2.R + p;
g = pixel1.G - pixel2.G + p;
b = pixel1.B - pixel2.B + p;
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;
bitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
}
}
return bitmap;
}
/// <summary>
/// 把图片转换为黑白
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
private static Bitmap ConvertToBackAndWhite(Bitmap source)
{
int sourceWidth = source.Width;
int sourceHeight = source.Height;
Bitmap result = new Bitmap(sourceWidth, sourceHeight);
double mid = 255d * (1d / 2d);
for (int x = 0; x < sourceWidth; x++)
{
for (int y = 0; y < sourceHeight; y++)
{
Color c = source.GetPixel(x, y);
///加权转换法 比较精确
int luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);
//平均值转换法
// int luma = (int)(c.R + c.G + c.B )/3;
result.SetPixel(x, y, Color.FromArgb(luma, luma, luma));
}
}
return result;
}