两种颜色都是由用户自己定义的。
然后代码实现在固定的方块区域中,
第一种颜色到第二种颜色的渐变。
如何实现。

解决方案 »

  1.   

    var
      Color1,Color2:TColor;
      R,G,B:Byte;
      R1,G1,B1:Real;
      i:integer;
    begin
      Color1:=clWhite;//开始颜色
      Color2:=clBlack;//终止颜色  R:=GetRValue(Color1);
      G:=GetGValue(Color1);
      B:=GetBValue(Color1);  R1:=(GetRValue(Color2)-R)/100;
      G1:=(GetGValue(Color2)-G)/100;
      B1:=(GetBValue(Color2)-B)/100;  {}
      for i:=0 to 100 do
       begin
        R:=Round(R+R1);
        G:=Round(G+G1);
        B:=Round(B+B1);
        canvas.Pen.Color :=RGB(R,G,B);
        canvas.MoveTo(i,0);
        canvas.LineTo(i,20);
       end;
      

  2.   

    procedure TForm1.FormPaint(Sender: TObject);
    var
      i:Integer;
      C1,C2:TColor;
      f:Single;
    begin
      C1:=clBlue;
      C2:=clGreen;
      with Form1.Canvas do
        for i:=0 to ClientHeight do
        begin
          f:=i/ClientHeight;
          Pen.Color:=rgb(Round(GetRValue(C1)*f+GetRValue(C2)*(1-f)),
            Round(GetGValue(C1)*f+GetGValue(C2)*(1-f)),
            Round(GetBValue(C1)*f+GetBValue(C2)*(1-f)));
          MoveTo(0,i);
          LineTo(ClientWidth,i);
        end;
    end;
      

  3.   

    var
      C1,C2:TColor;
      R,G,B :Byte;
      R1,G1,B1:Real;
      i:integer;
      Dct:TRect;
      W:integer;
    begin
      W:=width;
      C1:=clWhite;//¿ªÊ¼ÑÕÉ«
      C2:=clBlack;//ÖÕÖ¹ÑÕÉ«  R1:=(GetRValue(C2)-R)/W;
      G1:=(GetGValue(C2)-G)/W;
      B1:=(GetBValue(C2)-B)/W;  for i:=0 to W-1  do
       begin
        R:=Round(GetRValue(C1)+R1*i);
        G:=Round(GetGValue(C1)+G1*i);
        B:=Round(GetBValue(C1)+B1*i);
        Canvas.Brush.Color:=    RGB(R,G,B);
        Dct:=Rect(i,1,(i+1),Form1.height);
        //ÿ´ÎË¢»æµÄ¾ØÐÎÇøÓò
        Canvas.FillRect(Dct);   end;