我想实现扇形的渐变,S是圆的半径
X1 := 0;
Y1 := 0;
X2 := S * 2;
Y2 := S * 2;
Canvas.Pie(
X1, Y1,
X2, Y2,
S + 2, 0 - 2,
0 - 2, S + 2
);
//渐变色,分2部分处理
sPic := (S div 4) / 32;
sTemp := 0;
sTemp1 := S * 2;
for i := 1 to 32 do
begin
Canvas.Brush.Color := RGB(3 * i + 127, 3 * i + 127, 3 * i + 127);
Canvas.Pie(Round(sTemp + sPic * i), Round(sTemp + sPic * i),
Round(sTemp1 - sPic * i), Round(sTemp1 - sPic * i),
S + 2, Round(sTemp + sPic * i) - 2,
Round(sTemp + sPic * i) - 2, S + 2
);
end;
结果显示出来的扇形是这样,好像是颜色没变,但是实际代码里颜色在改变的:
你的思路不对,图上留下的都是扇形的边框。应该改为画弧线。代码如下:
procedure TForm1.Button1Click(Sender: TObject);
var x1,x2,y1,y2,s,i:integer;
sPic:Double;
sTemp :integer;
sTemp1 :integer;
begin
s:=400;
with Image1 do
begin
X1 := 0;
Y1 := 0;
X2 := S * 2;
Y2 := S * 2;
Canvas.Pie(X1, Y1,
X2, Y2,
S + 2, 0 - 2,
0 - 2, S + 2);
//渐变色,分2部分处理
sPic := (S div 4) / 32;
sTemp := 0;
sTemp1 := S * 2;
for i := 1 to 128 do
begin
// Canvas.pen.Color := RGB(2*i, 2*i, 2*i);
if i<64 then Canvas.pen.Color := RGB(4*i, 4*i, 4*i)
else Canvas.pen.Color := RGB(254-4*i,254-4*i,254-4*i);
Canvas.Pen.Width:=6; // 边框宽度 5
Canvas.arc(Round(sTemp + sPic * i),
Round(sTemp + sPic * i),
Round(sTemp1 - sPic * i),
Round(sTemp1 - sPic * i),
S + 2,
Round(sTemp + sPic * i) - 2,
Round(sTemp + sPic * i) - 2,
S + 2);
end;
end;
end;