图片处理为浮雕和黑白效果


        /// <summary>
        /// 浮雕效果图
        /// </summary>
        /// <param name="SImage">原图</param>
        /// <param name="p">80左右</param>
        /// <returns></returns>
        public static Bitmap Relief(Bitmap SImage, int p)
        {
            int Height = SImage.Height;
            int Width = SImage.Width;
            Bitmap bitmap = new Bitmap(Width, Height);
            Bitmap MyBitmap = (Bitmap)SImage;
            Color pixel1, pixel2;
            for (int x = 0; x < Width - 1; x++)
            {
                for (int y = 0; y < Height - 1; y++)
                {
                    int r = 0, g = 0, b = 0;
                    pixel1 = MyBitmap.GetPixel(x, y);
                    pixel2 = MyBitmap.GetPixel(x + 1, y + 1);
                    r = pixel1.R - pixel2.R + p;
                    g = pixel1.G - pixel2.G + p;
                    b = pixel1.B - pixel2.B + p;
                    if (r > 255)
                        r = 255;
                    if (r < 0)
                        r = 0;
                    if (g > 255)
                        g = 255;
                    if (g < 0)
                        g = 0;
                    if (b > 255)
                        b = 255;
                    if (b < 0)
                        b = 0;
                    bitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
                }
            }
            return bitmap;
        }


        /// <summary>
        /// 把图片转换为黑白
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private static  Bitmap ConvertToBackAndWhite(Bitmap source)
        {
            int sourceWidth = source.Width;
            int sourceHeight = source.Height;
            Bitmap result = new Bitmap(sourceWidth, sourceHeight);
            double mid = 255d * (1d / 2d);

            for (int x = 0; x < sourceWidth; x++)
            {
                for (int y = 0; y < sourceHeight; y++)
                {
                    Color c = source.GetPixel(x, y);
                    ///加权转换法 比较精确
                  int luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);
                    //平均值转换法
                    //  int luma = (int)(c.R  + c.G   + c.B  )/3;
                  
                    result.SetPixel(x, y, Color.FromArgb(luma, luma, luma));
                }
            }
            return result;
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值