大家 我一直试图在Delphi中解决以下问题。 我想制作一个图像并制作一个抗锯齿的圆角。 我知道如何使用RoundRect使所有四个角都圆。但是,我似乎并不知道如何制作一个。 我一直试图解决这个问题:
procedure RoundCorner(var image: TBitmap; w,h : integer);
//w - width of an image
//h - height of an image
//radius can be set at 150 (rounded rect radius)
// image is the timage object received as var parameter
var
i, j :integer;
x, y :double;
begin
i:= w - Trunc(radius);
x:= 0;
y:= radius - sqrt(sqr(radius) - sqr(x));
while(i < w) do
begin
j:=0;
while(j <= y) do
begin
image.Canvas.Pixels[i-1,j]:=clWhite; //a colour of your choosing or just erase this line
j := j + 1;
end;
y:= radius - sqrt(sqr(radius) - sqr(x));
x := x + 1;
i := i + 1;
end;
end;
这很有效,但是我遇到了两个问题:
欢迎任何建议 感谢。
答案 0 :(得分:0)
首先,在您的情况下,“抗锯齿”意味着您的图像必须具有32位像素格式才能形成圆形透明角。第二件事是你不能通过Canvas访问alpha通道,你需要直接通过Scanline属性访问位图像素,或者使用像Graphics32或AGG这样的库。
实现圆角的另一种“现代”方法是使用FMX并将图像放在圆形内部并用圆角修剪。