有一张图片
我想将其处理成负片效果
我现在的做法是读入bitmap
然后遍历所有像素点,getpixel取出r,g,b然后用255减
再重新setpixel回去
方法很笨,不知道有没有什么高效率的算法.
现在这个方法处理一张1920*1080的图片一条线程需要10s 两条线程也需要4秒
效率上很不满意.求高效率算法.
------解决方案--------------------
------解决方案--------------------
- C# code
/// <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; }