来者有分,delphi中画斜线时,怎么消除锯齿,否则太难看了?

gsoft 2004-01-08 09:55:25
同上
...全文
470 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
gsoft 2004-01-09
  • 打赏
  • 举报
回复
Graphic32控件,那里有下载的地方
gsoft 2004-01-09
  • 打赏
  • 举报
回复
加急,help me, thank you
数字蛋糕 2004-01-09
  • 打赏
  • 举报
回复
找找反走样的算法!
此外有一套Graphic32的控件支持反走样,而且是免费的。
cll007 2004-01-09
  • 打赏
  • 举报
回复
源代码里面是画点,好象没有可以直接改线宽度的
不过可以将这个函数再包一下,可以近似改变宽度,端点出可能有些问题,效率也很底
procedure ABLine(x1,y1,x2,y2 : single; color : tcolor; canvas : tcanvas;LineWidth:integer=1);
var
i:integer;
begin
Assert(LineWidth>0,'LineWidth Less then 0');
if LineWidth=1 then
AALine(x1,y1,x2,y2,color, canvas )
else
begin
if abs((y2-y1)/(x2-x1))<=1 then
for i :=-(1+LineWidth) div 2 to (1+LineWidth) div 2 do
AALine(x1,y1+i,x2,y2+i,color, canvas )
else
for i :=-(1+LineWidth) div 2 to (1+LineWidth) div 2 do
AALine(x1+i,y1,x2+i,y2,color, canvas )
end;
end;

gsoft 2004-01-09
  • 打赏
  • 举报
回复
up
gsoft 2004-01-09
  • 打赏
  • 举报
回复
这有一段抗锯齿的源码.大家看看怎么改变宽度,我试过了,但线比较细,想让线的宽度加大,怎么改?

procedure AALine(x1,y1,x2,y2 : single; color : tcolor; canvas : tcanvas);

function CrossFadeColor(FromColor,ToColor : TColor; Rate : Single) : TColor;
var r,g,b : byte;
begin
r:=Round(GetRValue(FromColor)*Rate+GetRValue(ToColor)*(1-Rate));
g:=Round(GetGValue(FromColor)*Rate+GetGValue(ToColor)*(1-Rate));
b:=Round(GetBValue(FromColor)*Rate+GetBValue(ToColor)*(1-Rate));
Result:=RGB(r,g,b);
end;

procedure hpixel(x : single; y : integer);
var FadeRate : single;
begin
FadeRate:=x-trunc(x);
with canvas do
begin
pixels[trunc(x),y]:=CrossFadeColor(Color,Pixels[Trunc(x),y],1-FadeRate);
pixels[trunc(x)+1,y]:=CrossFadeColor(Color,Pixels[Trunc(x)+1,y],FadeRate);
end;
end;

procedure vpixel(x : integer; y : single);
var FadeRate : single;
begin
FadeRate:=y-trunc(y);
with canvas do
begin
pixels[x,trunc(y)]:=CrossFadeColor(Color,Pixels[x,Trunc(y)],1-FadeRate);
pixels[x,trunc(y)+1]:=CrossFadeColor(Color,Pixels[x,Trunc(y)+1],FadeRate);
end;
end;

var i : integer;
ly,lx,currentx,currenty,deltax,deltay,l,skipl : single;
begin
if (x1<>x2) or (y1<>y2) then
begin
currentx:=x1;
currenty:=y1;
lx:=abs(x2-x1);
ly:=abs(y2-y1);

if lx>ly then
begin
l:=trunc(lx);
deltay:=(y2-y1)/l;
if x1>x2 then
begin
deltax:=-1;
skipl:=(currentx-trunc(currentx));
end else
begin
deltax:=1;
skipl:=1-(currentx-trunc(currentx));
end;
end else
begin
l:=trunc(ly);
deltax:=(x2-x1)/l;
if y1>y2 then
begin
deltay:=-1;
skipl:=(currenty-trunc(currenty));
end else
begin
deltay:=1;
skipl:=1-(currenty-trunc(currenty));
end;
end;

currentx:=currentx+deltax*skipl;
currenty:=currenty+deltay*skipl;{}

for i:=1 to trunc(l) do
begin
if lx>ly then vpixel(trunc(currentx),currenty) else hpixel(currentx,trunc(currenty));
currentx:=currentx+deltax;
currenty:=currenty+deltay;
end;

end;
BlueTrees 2004-01-09
  • 打赏
  • 举报
回复
我的建议:

你自己建立一个反锯齿算法,这种算法很简单,我提供一种:

你画线变粗一个像素,在那个线画之前,画你的那变粗的那条线,那条线的颜色和画的目标线一样,采用半透明算法(半透明算法可以找得到)覆盖在底色上。不透明的程度33%。这样,后面画的线就不会有很强的锯齿感了,圆弧等等其他线都是一个办法。
ly_liuyang 2004-01-09
  • 打赏
  • 举报
回复
GUI的没有办法

就是没发解决了

除非DirectX+抗锯齿技术,还要你的显卡支持
gsoft 2004-01-08
  • 打赏
  • 举报
回复
不可能,我机器上有一个程序是用VC开发的,画的斜线就没有锯齿
whyNotHere 2004-01-08
  • 打赏
  • 举报
回复
只有提高分辨率这一个办法,不会有第2个办法! 这是计算机硬件决定的,不是
程序的问题。
solokey 2004-01-08
  • 打赏
  • 举报
回复
提高分辨率
gsoft 2004-01-08
  • 打赏
  • 举报
回复
up,急急急

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧