本文介绍了如何绘制“不”彩色文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种用反转颜色绘制文字的方式。
对于形状,我们可以将 TPenMode
设置为 pmNot
,但是我们不能这样做为文本。
I'm looking for a way to draw text with inverted colors.For shapes, we have TPenMode
that can be set to pmNot
, but we can't do this for text. How can I do this instead?
推荐答案
这样做:
procedure DrawTextNOT(const hDC: HDC; const Font: TFont; const Text: string; const X, Y: integer);
begin
with TBitmap.Create do
try
Canvas.Font.Assign(Font);
with Canvas.TextExtent(Text) do
SetSize(cx, cy);
Canvas.Brush.Color := clBlack;
Canvas.FillRect(Rect(0, 0, Width, Height));
Canvas.Font.Color := clWhite;
Canvas.TextOut(0, 0, Text);
BitBlt(hDC, X, Y, Width, Height, Canvas.Handle, 0, 0, SRCINVERT);
finally
Free;
end;
end;
示例:
procedure TForm1.FormClick(Sender: TObject);
begin
Canvas.Brush.Color := clRed;
Canvas.FillRect(ClientRect);
DrawTextNOT(Canvas.Handle, Canvas.Font, 'This is a test.', 20, 100);
// DrawTextNOT(Canvas.Handle, Canvas.Font, 'This is a test.', 20, 100);
end;
您可能还想禁用ClearType。为了做到这一点,我转介你。
You probably also want to disable ClearType. To do that, I refer you to a previous SO question.
这篇关于如何绘制“不”彩色文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!