当前位置:编程学习 > C#/ASP.NET >>

C#实现图像gamma曲线调整

//gamma值是用曲线表示的,这是一种人的眼睛对光的一种感应曲线,其中包括了物理量、身理感官及心理的感知度
        /**//// <summary>
        /// Gamma校正
        /// </summary>
        /// <param name="bmp">输入Bitmap</param>
        /// <param name="val">[0 <-明- 1 -暗-> 2]</param>
        /// <returns>输出Bitmap</returns>
        public static Bitmap KiGamma(Bitmap bmp, float val)
        {
            if (bmp == null)
            {
                return null;
            }

            // 1表示无变化,就不做
            if (val == 1.0000f) return bmp;

            try
            {
                Bitmap b = new Bitmap(bmp.Width, bmp.Height);
                Graphics g = Graphics.FromImage(b);
                ImageAttributes attr = new ImageAttributes();

                attr.SetGamma(val, ColorAdjustType.Bitmap);
                g.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attr);
                g.Dispose();
                return b;
            }
            catch
            {
                return null;
            }
        } --------------------编程问答--------------------   占个好位,才能顶好
补充:.NET技术 ,  非技术区
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,