首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

求更精细的两种颜色渐变!该怎么处理

2012-02-22 
求更精细的两种颜色渐变!procedure TForm1.Button1Click(Sender: TObject)constCOLORDEL 300//控制渐

求更精细的两种颜色渐变!
procedure TForm1.Button1Click(Sender: TObject);
const
 COLORDEL = 300;//控制渐变的细致程度
var
 ColorS, ColorE: TColor;
 I, X, Y, nX, nY: Integer;
 rDel: Real;
 nRed, nGreen, nBlue: Integer;
begin
 ColorS := clBlack;//起始颜色,默认为黑
 ColorE := clWhite;//终止颜色,默认为白
 with ColorDialog1 do begin
  if Execute then ColorS := Color;
  if Execute then ColorE := Color;
 end;
 X := 0;
 Y := 0;
 nX := Width div COLORDEL;
 nY := Height;
 nRed := GetRValue(ColorS);
 nGreen := GetGValue(ColorS);
 nBlue := GetBValue(ColorS);
 for I := 0 to COLORDEL - 1 do begin
  Canvas.Brush.Color := RGB(nRed, nGreen, nBlue);
  Canvas.FillRect(Rect(X, Y, X + nX, Y + nY));
  rDel := nX * I / Width;//关键!根据距离渐变
  Inc(X, nX);
  nRed := Round(GetRValue(ColorS) + (GetRValue(ColorE) - GetRValue(ColorS)) * rDel);
  nGreen := Round(GetGValue(ColorS) + (GetGValue(ColorE) - GetGValue(ColorS)) * rDel);
  nBlue := Round(GetBValue(ColorS) + (GetBValue(ColorE) - GetBValue(ColorS)) * rDel);
 end;
 Canvas.FillRect(Rect(X, Y, Left + Width, Top + Height));//保证最右侧充分填充
end;

以上是大富翁论坛的帖子,但精细度不够,COLORDEL设置上1000就不会变化了,请问有没有更好的算法?谢谢!

[解决办法]
楼主可以参考RZ组件试试。
[解决办法]
来学习下。
[解决办法]
恕我愚昧,我还没看明白你那个COLORDEL怎么控制精细程度的,如果Width < COLORDEL,nX 且不为0?

热点排行