关于如何画出清晰的虚线框(100分)

D

DickWu

Unregistered / Unconfirmed
GUEST, unregistred user!
我用下面的语句画虚线框:
OldColor := Canvas.Pen.Color;
OldMode := CanVas.Pen.Mode;
OldStyle := CanVas.Pen.Style;
Canvas.Pen.Color:= clBlack;
CanVas.Pen.Mode := pmNotXor;
CanVas.Pen.Style:= psDot;
Canvas.Rectangle(aRect.Left,aRect.top,aRect.right,arect.bottom);
Canvas.Pen.Color:= OldColor;
CanVas.Pen.Mode := OldMode;
CanVas.Pen.Style:= OldStyle;
但是发现在黑色和白色背景和下可以看见虚线,在clGray背景下却看不见虚线。

我需要一种在任何背景(比如各种背景色,或者各种彩色图片作背景)下都
可以清晰显示的虚线和虚线框的画法

有哪位大哥愿意帮帮我嘛?
 
对Pen.color求反色调
 
什么意思? 求哪个颜色的反色调?
我试了不少颜色,好象在clGray下都画不出虚线来
 
procedure TForm1.FormPaint(Sender: TObject);
begin
DrawFocusRect(Canvas.Handle, Rect(0,0,100,100))
end;
不可以么?
 
DrawFocusRect能画虚线?
 
设置pen的 penmode 为 XOR
 
还是不行
 
可以考虑用一个BMP来保存四条线的东西,
再直接画线(比如该处的亮度小于128则画白线,大于128则画黑线等),
移动后在将保存的东西恢复.....如此反复。
 
这个办法也太......
 
用蚂蚁线可以吗?试试看。
 
用蚂蚁线,以前卷兄有蚂蚁线的例子
 
首先要了解NotXor是怎么操作的.
假设笔色是黑色(即000000H),底色是白色(即FFFFFFH),
not (000000H xor FFFFFFH) = not FFFFFFH = 000000H
所以结果绘图时使用的是000000H(即黑色)
如果底色是灰色(7F7F7FH),
not (000000H xor 7F7F7FH) = not 7F7F7FH = 808080H
结果绘图时使用的是808080H(与7F7F7FH相当接近,肉眼无法分辨)

再看Xor的操作:
000000H xor 7F7F7FH = 7F7F7FH
绘图时使用的是7F7F7FH(即灰色,同时也是底色,肉眼这更无法分辩了)

解决方法:
1 用Copy方式绘图吧
2 用其他画笔颜色吧
 
看过一篇很欣赏的文章,内容是以前的程序员很喜欢在空隙时。
用公司的计算机编一些高效率的图形程序,当时是286。
其中有一个是虫子吞食问题,不管屏幕图象是怎样的,都能清楚看到虫子,
虫子能走过任何地方,走过的地方可以被虫子吃掉,或恢复原样。
为了效率不需要用变量保存象点。反正是Xor过来,Xor过去就行了。
在窗体上画虚线框的要不要
private
{ Private declarations }
Capturing: bool;
Captured: bool;
StartPlace: TPoint;
EndPlace: TPoint;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

function MakeRect(Pt1: TPoint;
Pt2: TPoint): TRect;
begin
if pt1.x < pt2.x then
begin
Result.Left := pt1.x;
Result.Right := pt2.x;
end
else
begin
Result.Left := pt2.x;
Result.Right := pt1.x;
end;
if pt1.y < pt2.y then
begin
Result.Top := pt1.y;
Result.Bottom := pt2.y;
end
else
begin
Result.Top := pt2.y;
Result.Bottom := pt1.y;
end;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Captured then
DrawFocusRect(Form1.Canvas.Handle,
MakeRect(StartPlace,
EndPlace));
StartPlace.x := X;
StartPlace.y := Y;
EndPlace.x := X;
EndPlace.y := Y;
DrawFocusRect(Form1.Canvas.Handle,
MakeRect(StartPlace,
EndPlace));
Capturing := true;
Captured := true;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Capturing then
begin
DrawFocusRect(Form1.Canvas.Handle,
MakeRect(StartPlace,
EndPlace));
EndPlace.x := X;
EndPlace.y := Y;
DrawFocusRect(Form1.Canvas.Handle,
MakeRect(StartPlace,
EndPlace));

// StartPlace.x := X;
// StartPlace.y := Y;
// EndPlace.x := X;
// EndPlace.y := Y;
Form1.Caption := '(' + inttostr(StartPlace.x) + ',' + inttostr(StartPlace.y)
+ ')';
Form1.Caption := Form1.Caption + ' - (' + inttostr(EndPlace.x) + ',' +
inttostr(EndPlace.y) + ')';
end;

end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Capturing := false;
end;
你可以把虚线框画成顺时针跑动的,象一些绘图软件那样。
 
顶部