C# 光源的渐变生成算法

光源的渐变生成算法



        private Bitmap CreateLightBitmap(Int32 Width,Int32 Height,Color Source,Color Destinat,Int32 s_low = -1)
        {
            Bitmap Bmp = new Bitmap(Width, Height);
            Point Center = new Point(Width / 2, Height/2);
            Int32 low = Math.Min(Center.X, Center.Y);
            if (s_low > 0) low = s_low;
            Int32 A = Destinat.A - Source.A;
            Int32 R = Destinat.R - Source.R;
            Int32 G = Destinat.G - Source.G;
            Int32 B = Destinat.B - Source.B;
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    Double _Value = Math.Sqrt(Math.Pow(Math.Abs(x - Center.X), 2) + Math.Pow(Math.Abs(y - Center.Y), 2));
                    if (_Value > low) _Value = low;
                    Double _bf = _Value / low * 100;
                    Double _A = _bf / 100 * A;
                    Double _R = _bf / 100 * R;
                    Double _G = _bf / 100 * G;
                    Double _B = _bf / 100 * B;
                    Color nColor = Color.FromArgb(Source.A + (Int32)_A, Source.R + (Int32)_R,  Source.G + (Int32)_G, Source.B + (Int32)_B);
                    Bmp.SetPixel(x, y, nColor);
                }
            }
            return Bmp;
        }

            Bitmap Bmp = CreateLightBitmap(400, 400, Color.Red, Color.Transparent);
            Bmp.Save("C:\\123.png", ImageFormat.Png);
            pictureBox1.Image = Bmp;



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值