Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,627 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
how to create shadow effect using direct2d to line or rectangle?
I know I can create shadow on ID2D1Image.but Can I create it on line or rectangle?
when I fill rectangle can I create its shaodow? or when I Draw Rectangle can I draw it's shadow?
You can add a Shadow effect on anything you draw .
For example on a blue Rectangle :
pDeviceContext->BeginDraw();
pDeviceContext->Clear(D2D1::ColorF(D2D1::ColorF::White, 1.0f));
D2D1_SIZE_F renderTargetSize = pDeviceContext->GetSize();
ID2D1BitmapRenderTarget* pCompatibleRenderTarget = NULL;
HRESULT hr = pDeviceContext->CreateCompatibleRenderTarget(renderTargetSize, &pCompatibleRenderTarget);
if (SUCCEEDED(hr))
{
pCompatibleRenderTarget->BeginDraw();
//pCompatibleRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White, 1.0f));
pCompatibleRenderTarget->Clear(NULL);
ID2D1SolidColorBrush* pBlackBrush = NULL;
pCompatibleRenderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &pBlackBrush);
pCompatibleRenderTarget->FillRectangle(D2D1::RectF(50.f, 50.f, 250.f, 250.f), pBlackBrush);
SafeRelease(&pBlackBrush);
pCompatibleRenderTarget->EndDraw();
ID2D1Bitmap* pCompatibleBitmap = NULL;
hr = pCompatibleRenderTarget->GetBitmap(&pCompatibleBitmap);
if (SUCCEEDED(hr))
{
ID2D1Effect* pShadowEffect = NULL;
hr = pDeviceContext->CreateEffect(CLSID_D2D1Shadow, &pShadowEffect);
if (SUCCEEDED(hr))
{
pShadowEffect->SetValue(D2D1_SHADOW_PROP_BLUR_STANDARD_DEVIATION, 5.f);
pShadowEffect->SetInput(0, pCompatibleBitmap);
pDeviceContext->DrawImage(pShadowEffect,
D2D1::Point2F(10, 10),
D2D1::RectF(0, 0, renderTargetSize.width, renderTargetSize.height),
D2D1_INTERPOLATION_MODE_LINEAR,
D2D1_COMPOSITE_MODE_SOURCE_OVER
);
SafeRelease(&pShadowEffect);
}
SafeRelease(&pCompatibleBitmap);
}
SafeRelease(&pCompatibleRenderTarget);
ID2D1SolidColorBrush* pBlueBrush = NULL;
pDeviceContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Blue), &pBlueBrush);
pDeviceContext->FillRectangle(D2D1::RectF(50.f, 50.f, 250.f, 250.f), pBlueBrush);
SafeRelease(&pBlueBrush);
}
pDeviceContext->EndDraw();