ID2D1RenderTarget::FillRoundedRectangle (constD2D1_ROUNDED_RECT&,ID2D1Brush*) 方法 (d2d1.h)
绘制指定圆角矩形的内部。
语法
void FillRoundedRectangle(
const D2D1_ROUNDED_RECT & roundedRect,
[in] ID2D1Brush *brush
);
参数
roundedRect
类型:[in] const D2D1_ROUNDED_RECT &
要绘制的圆角矩形的维度(以设备无关像素为单位)。
[in] brush
类型:[in] ID2D1Brush*
用于绘制圆角矩形内部的画笔。
返回值
无
备注
如果此方法失败,此方法不会返回错误代码。 若要确定绘制操作 ((如 FillRoundedRectangle) )是否失败,检查 ID2D1RenderTarget::EndDraw 或 ID2D1RenderTarget::Flush 方法返回的结果。
示例
以下示例使用 DrawRoundedRectangle 和 FillRoundedRectangle 方法来轮廓和填充圆角矩形。 此示例生成如下图所示的输出。
// Called whenever the application needs to display the client
// window.
HRESULT DrawAndFillRoundedRectangleExample::OnRender()
{
HRESULT hr;
// Create the render target and brushes if they
// don't already exists.
hr = CreateDeviceResources();
if (SUCCEEDED(hr))
{
// Retrieve the size of the render target.
D2D1_SIZE_F renderTargetSize = m_pRenderTarget->GetSize();
m_pRenderTarget->BeginDraw();
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));
// Paint a grid background.
m_pRenderTarget->FillRectangle(
D2D1::RectF(0.0f, 0.0f, renderTargetSize.width, renderTargetSize.height),
m_pGridPatternBitmapBrush
);
// Define a rounded rectangle.
D2D1_ROUNDED_RECT roundedRect = D2D1::RoundedRect(
D2D1::RectF(20.f, 20.f, 150.f, 100.f),
10.f,
10.f
);
// Draw the rectangle.
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pBlackBrush, 10.f);
// Apply a translation transform.
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(200.f, 0.f));
// Draw the rounded rectangle again, this time with a dashed stroke.
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pBlackBrush, 10.f, m_pStrokeStyle);
// Apply another translation transform.
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(0.f, 150.f));
// Draw, then fill the rounded rectangle.
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pBlackBrush, 10.f, m_pStrokeStyle);
m_pRenderTarget->FillRoundedRectangle(roundedRect, m_pSilverBrush);
// Apply another translation transform.
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(200.f, 150.f));
// Fill, then draw the rounded rectangle.
m_pRenderTarget->FillRoundedRectangle(roundedRect, m_pSilverBrush);
m_pRenderTarget->DrawRoundedRectangle(roundedRect, m_pBlackBrush, 10.f, m_pStrokeStyle);
hr = m_pRenderTarget->EndDraw();
if (hr == D2DERR_RECREATE_TARGET)
{
hr = S_OK;
DiscardDeviceResources();
}
}
return hr;
}
要求
要求 | 值 |
---|---|
最低受支持的客户端 | Windows 7、带 SP2 的 Windows Vista 和适用于 Windows Vista 的平台更新 [桌面应用 |UWP 应用] |
最低受支持的服务器 | Windows Server 2008 R2、Windows Server 2008 SP2 和适用于 Windows Server 2008 的平台更新 [桌面应用 |UWP 应用] |
目标平台 | Windows |
标头 | d2d1.h |
Library | D2d1.lib |
DLL | D2d1.dll |