# 如何繪製和填滿複雜圖形

Direct2D 提供 ID2D1PathGeometry介面，用來描述可包含曲線、弧線和線條的複雜圖形。 本主題描述如何定義和轉譯路徑幾何。

``````ID2D1GeometrySink *pSink = NULL;

// Create a path geometry.
if (SUCCEEDED(hr))
{
hr = m_pD2DFactory->CreatePathGeometry(&m_pPathGeometry);

if (SUCCEEDED(hr))
{
// Write to the path geometry using the geometry sink.
hr = m_pPathGeometry->Open(&pSink);

if (SUCCEEDED(hr))
{
pSink->BeginFigure(
D2D1::Point2F(0, 0),
D2D1_FIGURE_BEGIN_FILLED
);

D2D1::BezierSegment(
D2D1::Point2F(150, 50),
D2D1::Point2F(150, 150),
D2D1::Point2F(200, 200))
);

D2D1::BezierSegment(
D2D1::Point2F(50, 150),
D2D1::Point2F(50, 50),
D2D1::Point2F(0, 0))
);

pSink->EndFigure(D2D1_FIGURE_END_CLOSED);

hr = pSink->Close();
}
SafeRelease(&pSink);
}
}
``````

``````if (SUCCEEDED(hr))
{
// Create a black brush.
hr = m_pRenderTarget->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::Black),
&m_pBlackBrush
);
}

if (SUCCEEDED(hr))
{
{
{   0.f,  { 0.f, 1.f, 1.f, 0.25f }  },
{   1.f,  { 0.f, 0.f, 1.f, 1.f }  },
};

stops,
ARRAYSIZE(stops),
);

if (SUCCEEDED(hr))
{
D2D1::Point2F(100, 0),
D2D1::Point2F(100, 200)),
D2D1::BrushProperties(),
&m_pLGBrush
);
}

}
``````

``````void DemoApp::RenderGeometryExample()
{
// Translate subsequent drawings by 20 device-independent pixels.
m_pRenderTarget->SetTransform(
D2D1::Matrix3x2F::Translation(20.f, 20.f)
);

// Draw the hour glass geometry at the upper left corner of the client area.
m_pRenderTarget->DrawGeometry(m_pPathGeometry, m_pBlackBrush, 10.f);
m_pRenderTarget->FillGeometry(m_pPathGeometry, m_pLGBrush);
}
``````