Как нарисовать круг с ID2D1PathGeometry

ID2D1PathGeometry :: Open возвращает ID2D1GeometrySink, который поддерживает добавление линий, дуг и кривых. Но есть ли способ добавить круг (эллипс) или хотя бы как-то смоделировать его?

2

Решение

С помощью функции AddArc вы можете просто нарисовать две дуги с одинаковыми радиусами x и y, чтобы построить круг. Вот изображение и код, надеюсь, это поможет вам.

введите описание изображения здесь

// create circle with two arcs
hr = g_pD2DFactory->CreatePathGeometry(&g_pCircleGeometry) ;
if (SUCCEEDED(hr))
{
ID2D1GeometrySink *pSink = NULL;

hr = g_pCircleGeometry->Open(&pSink);
if (SUCCEEDED(hr))
{
pSink->SetFillMode(D2D1_FILL_MODE_WINDING);

pSink->BeginFigure(
D2D1::Point2F(100, 300), // Start point of the top half circle
D2D1_FIGURE_BEGIN_FILLED
);

// Add the top half circle
pSink->AddArc(
D2D1::ArcSegment(
D2D1::Point2F(400, 300), // end point of the top half circle, also the start point of the bottom half circle
D2D1::SizeF(150, 150), // radius
0.0f, // rotation angle
D2D1_SWEEP_DIRECTION_CLOCKWISE,
D2D1_ARC_SIZE_SMALL
));

// Add the bottom half circle
pSink->AddArc(
D2D1::ArcSegment(
D2D1::Point2F(100, 300), // end point of the bottom half circle
D2D1::SizeF(150, 150),   // radius of the bottom half circle, same as previous one.
0.0f, // rotation angle
D2D1_SWEEP_DIRECTION_CLOCKWISE,
D2D1_ARC_SIZE_SMALL
));

pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
}
hr = pSink->Close();
SAFE_RELEASE(pSink);
}
5

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector