gpt4 book ai didi

delphi - 在 TBitmap 周围绘制点的边界线?

转载 作者:行者123 更新时间:2023-12-03 15:44:41 26 4
gpt4 key购买 nike

我编写了一个例程,应该向位图添加点线边框:

procedure AddDottedBorderToBitmap(aBM: Vcl.Graphics.TBitmap);
var
c: TCanvas;
begin
c := aBM.Canvas;
c.Pen.Color := clBlack;
c.Pen.Mode := pmXor;
c.Pen.Style := psDot;

c.MoveTo(0, 0);
c.LineTo(0, aBM.Height - 1);
c.LineTo(aBM.Width - 1, aBM.Height - 1);
c.LineTo(aBM.Width - 1, 0);
c.LineTo(0, 0);
end;

但是当放大结果时,生成的边界线而不是点似乎是由小破折号组成的:

enter image description here

这是正确的吗?如果没有,我怎样才能得到真正的点而不是破折号?

最佳答案

使用DrawFocusRect似乎很简单,但如果您需要绘制矩形以外的其他内容,您可能需要提前阅读。

笔样式psDot并不意味着每隔一个像素就被着色而另一个像素被清除。如果您考虑一下,分辨率越高,就越难看出点状与灰色实心 f.ex 的差异。还有另一种笔样式 psAlternate 可以交替像素。文档说:

psAlternate

The pen sets every other pixel. (This style is applicable only for cosmetic pens.) This style is only valid for pens created with the ExtCreatePen API function. (See MS Windows SDK docs.) This applies to both VCL and VCL.NET.

要定义笔并使用它,我们按如下方式操作

var
c: TCanvas;
oldpenh, newpenh: HPEN; // pen handles
lbrush: TLogBrush; // logical brush

...

c := pbx.Canvas; // pbx is a TPintBox, but can be anything with a canvas

lbrush.lbStyle := BS_SOLID;
lbrush.lbColor := clBlack;
lbrush.lbHatch := 0;

// create the pen
newpenh := ExtCreatePen(PS_COSMETIC or PS_ALTERNATE, 1, lbrush, 0, nil);
try
// select it
oldpenh := SelectObject(c.Handle, newpenh);

// use the pen
c.MoveTo(0, 0);
c.LineTo(0, pbx.Height - 1);
c.LineTo(pbx.Width - 1, pbx.Height - 1);
c.LineTo(pbx.Width - 1, 0);
c.LineTo(0, 0);

c.Ellipse(3, 3, pbx.width-3, pbx.Height-3);

// revert to the old pen
SelectObject(c.Handle, oldpenh);
finally
// delete the pen
DeleteObject(newpenh);
end;

最后是它的样子(放大镜放大倍数为 10 倍)

enter image description here

关于delphi - 在 TBitmap 周围绘制点的边界线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44659359/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com