日期:2014-05-20 浏览次数:21111 次
/// <summary> /// 反色,即底片效果 /// </summary> /// <param name="imgIn">输入的源图片</param> /// <returns>处理后的图片</returns> public static Image Negative(Image imgIn) { if (null == imgIn) throw new Exception(); int iHeight = imgIn.Height; int iWidth = imgIn.Width; Bitmap newBitmap = new Bitmap(iWidth, iHeight); Bitmap oldBitmap = imgIn as Bitmap; try { Color pixel;//表示一个像素点 for (int x = 1; x < iWidth; x++) { for (int y = 1; y < iHeight; y++) { int r, g, b;//分别表示一个像素点红,绿,蓝的分量。 pixel = oldBitmap.GetPixel(x, y); r = 255 - pixel.R; g = 255 - pixel.G; b = 255 - pixel.B; newBitmap.SetPixel(x, y, Color.FromArgb(pixel.A,r, g, b)); } } } catch (Exception ee) { throw new Exception(); } return newBitmap; }