1.效果图:

(曝光效果) (霓虹效果)
2.实现原理:
曝光效果:逆转值小于128的R、G、B分量值,产生正片和负片混合的效果。
霓虹效果:用来描绘图像的轮廓,勾画颜色变化的边缘,加强其过度效果,产生轮廓发光的效果。
主要是根据当前像素与其右方和下方像素的梯度运算,然后将结果值作为当前像素值,
即将原图像当前像素的R、G、B分量与其右方和下方像素做梯度运算(差的平方和的平方根),
然后将梯度值作为处理后像素的R、G、B的三个分量。
[ result = Math.Sqrt( (src-right)*(src-right) + (src-bottom)*(src-bottom) ) ]
3.实现代码:
public static Image Solarize(Image img)
{
int width = img.Width;
int height = img.Height;
Bitmap bmp = new Bitmap(img);
Rectangle rect = new Rectangle(0, 0, width, height);
ImageLockMode flag = ImageLockMode.ReadWrite;
PixelFormat format = PixelFormat.Format32bppArgb;
BitmapData data = bmp.LockBits(rect, flag, format);
IntPtr ptr = data.Scan0;
int numBytes = width * height * 4;
byte[] rgbValues = new byte[numBytes];
Marshal.Copy(ptr, rgbValues, 0, numBytes);
for (int i = 0; i < rgbValues.Length; i += 4)
{
if (rgbValues[i] < 128)
rgbValues[i] = (byte)(255 - rgbValues[i]);
if (rgbValues[i + 1] < 128)
rgbValues[i + 1] = (byte)(255 - rgbValues[i + 1]);
if (rgbValues[i + 2] < 128)
rgbValues[i + 2] = (byte)(255 - rgbValues[i + 2]);
}
Marshal.Copy(rgbValues, 0, ptr, numBytes);
bmp.UnlockBits(data);
return (Image)bmp;
}
public static Image GlowingEdge(Image img)
{
int width = img.Width;
int height = img.Height;
Bitmap oldImg = (Bitmap)img;
Bitmap newImg = new Bitmap(width, height);
Color c1, c2, c3;
int rr, gg, bb;
for (int i = 0; i < width - 1; i++)
{
for (int j = 0; j < height - 1; j++)
{
int r = 0, g = 0, b = 0;
c1 = oldImg.GetPixel(i, j);
c2 = oldImg.GetPixel(i + 1, j);
c3 = oldImg.GetPixel(i, j + 1);
rr = (c1.R - c2.R) * (c1.R - c2.R) + (c1.R - c3.R) * (c1.R - c3.R);
gg = (c1.G - c2.G) * (c1.G - c2.G) + (c1.G - c3.G) * (c1.G - c3.G);
bb = (c1.B - c2.B) * (c1.B - c2.B) + (c1.B - c3.B) * (c1.B - c3.B);
r = (int)(3 * Math.Sqrt(rr));
g = (int)(3 * Math.Sqrt(gg));
b = (int)(3 * Math.Sqrt(bb));
r = r < 0 ? 0 : r;
r = r > 255 ? 255 : r;
g = g < 0 ? 0 : g;
g = g > 255 ? 255 : g;
b = b < 0 ? 0 : b;
b = b > 255 ? 255 : b;
newImg.SetPixel(i, j, Color.FromArgb(r, g, b));
}
}
return newImg;
}
4.说明:
曝光效果采用的是LockBits方法,霓虹效果采用的是GetPixel、SetPixel方法。
可比较这两种方法在处理图像上的效率问题。
图像处理--曝光、霓虹(照亮边缘效果),布布扣,bubuko.com
原文:http://www.cnblogs.com/jameslong/p/3805995.html