专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > .NET分析设计

怎么高效率的实现图片负片处理

发布时间:2011-06-23 20:39:10 文章来源:www.iduyao.cn 采编人员:星星草
如何高效率的实现图片负片处理
有一张图片
我想将其处理成负片效果
我现在的做法是读入bitmap
然后遍历所有像素点,getpixel取出r,g,b然后用255减
再重新setpixel回去

方法很笨,不知道有没有什么高效率的算法.

现在这个方法处理一张1920*1080的图片一条线程需要10s 两条线程也需要4秒 
效率上很不满意.求高效率算法.

------解决方案--------------------
探讨

C# code

pubic unsafe void 反色(Bitmap bmp)
{
BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
……

------解决方案--------------------
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;
        }
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: