如何在C ++ Builder中绘制Direct2D透明线

时间:2015-07-13 22:48:30

标签: delphi c++builder direct2d

我正在使用C ++ Builder XE4和VCL windows平台,我使用包装器TDirect2DCanvas来访问Direct2D功能。我将GDI +代码移植到Direct2D,并且我仍然坚持如何在Direct2D中绘制透明线。当我说透明时,我会想要使用某种类型的alpha混合或透明设置,以便可以看到线下的图像。下面的代码创建一个Direct2D渐变画笔,并在Direct2D渲染目标上绘制一条线,但没有透明度。你能说明如何设置画笔和/或笔,以便线条绘制透明。感谢

// begin drawing
Canvas2D_->BeginDraw();
try
{
TColor clrs[] = {clRed, clLime};
// create a gradient brush
DelphiInterface<ID2D1Brush> pBrush =
Canvas->CreateBrush(clrs, 1,
D2D1::Point2F(-w/2, -h/2),
D2D1::Point2F(w/2, h/2));
Canvas->Brush->Handle = pBrush;

Canvas->Pen->Width = 10;
int x=25;
Canvas->MoveTo(x, -half_h);
Canvas->LineTo(x, half_h);

}
__finally
{
// end drawing (actual screen update)
Canvas2D_->EndDraw();
} 

1 个答案:

答案 0 :(得分:1)

尝试在画笔上调用ID2D1Brush :: SetOpacity,其值介于0.0和1.0之间,具体取决于您对该行的透明度:

DelphiInterface<ID2D1Brush> pBrush = // ...
pBrush->SetOpacity(0.5);