当我在玩这个 MSDN 示例时,我只是无法在由 DXGISurface 创建并填充了一些矩形的 ID2D1Image 上添加模糊效果。
这是我的EndDraw
方法:
void Scenario1ImageSource::EndDraw()
{
// Remove the transform and clip applied in BeginDraw since
// the target area can change on every update.
m_d2dContext->SetTransform(D2D1::IdentityMatrix());
m_d2dContext->PopAxisAlignedClip();
DX::ThrowIfFailed(
m_d2dContext->Flush()
);
ComPtr<ID2D1Image> bitmap;
m_d2dContext->GetTarget(&bitmap);
DX::ThrowIfFailed(
m_d2dContext->CreateEffect(CLSID_D2D1GaussianBlur, &m_gaussianBlurEffect)
);
m_gaussianBlurEffect->SetInput(0, bitmap.Get());
DX::ThrowIfFailed(
m_gaussianBlurEffect->SetValue(D2D1_GAUSSIANBLUR_PROP_STANDARD_DEVIATION, 3.0f)
);
DX::ThrowIfFailed(
m_gaussianBlurEffect->SetValue(D2D1_GAUSSIANBLUR_PROP_BORDER_MODE, D2D1_BORDER_MODE_HARD)
);
m_d2dContext->BeginDraw();
m_d2dContext->DrawImage(m_gaussianBlurEffect.Get());
// Remove the render target and end drawing.
DX::ThrowIfFailed(
m_d2dContext->EndDraw()
);
m_d2dContext->SetTarget(nullptr);
// Query for ISurfaceImageSourceNative interface.
Microsoft::WRL::ComPtr<ISurfaceImageSourceNative> sisNative;
DX::ThrowIfFailed(
reinterpret_cast<IUnknown*>(this)->QueryInterface(IID_PPV_ARGS(&sisNative))
);
DX::ThrowIfFailed(
sisNative->EndDraw()
);
}
我想在他们在图像上绘制后模糊我的矩形。为什么它通过抛出带有错误代码 D2DERR_INVALID_GRAPH_CONFIGURATION 的异常而失败?