画渐变函数

代码

procedure ColorFul(_Sender:TCanvas;_C1,_C2:TColor;_Width,_Height:Integer;_Mode:Integer);
var i:Integer;Rct:TRect;R1,G1,B1,R2,G2,B2,R3,G3,B3:Byte;
begin
  with TCanvas(_Sender) do begin
    R1:=Byte(_C1);
    G1:=Byte(_C1 shr 8);
    B1:=Byte(_C1 shr 16);
    R2:=Byte(_C2);
    G2:=Byte(_C2 shr 8);
    B2:=Byte(_C2 shr 16);
    case _Mode of
    1:begin
      for i:=0 to _Width do begin
        if R1>R2 then R3:=R1-MulDiv(i,R1-R2,_Width) else R3:=R1+MulDiv(i,R2-R1,_Width);
        if G1>G2 then G3:=G1-MulDiv(i,G1-G2,_Width) else G3:=G1+MulDiv(i,G2-G1,_Width);
        if B1>B2 then B3:=B1-MulDiv(i,B1-B2,_Width) else B3:=B1+MulDiv(i,B2-B1,_Width);
        Brush.Color:=RGB(R3,G3,B3);
        Rct:=Rect(i,0,i+1,_Height);
        FillRect(Rct);
      end;
    end;
    2:begin
      for i:=0 to _Height do begin
        if R1>R2 then R3:=R1-MulDiv(i,R1-R2,_Height) else R3:=R1+MulDiv(i,R2-R1,_Height);
        if G1>G2 then G3:=G1-MulDiv(i,G1-G2,_Height) else G3:=G1+MulDiv(i,G2-G1,_Height);
        if B1>B2 then B3:=B1-MulDiv(i,B1-B2,_Height) else B3:=B1+MulDiv(i,B2-B1,_Height);
        Brush.Color:=RGB(R3,G3,B3);
        Rct:=Rect(0,i,_Width,i+1);
        FillRect(Rct);
      end;
    end;
    end;
    SetBkMode(Handle,Windows.TRANSPARENT);
  end;
end;

用法

procedure TForm1.FormPaint(Sender: TObject);
begin
  ColorFul(Self.Canvas,clSkyBlue,clWhite,Self.Width,Self.Height,2);
//1是横着,2是竖着

end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值