How can I create a Gaussian blur with a printer render target using Direct2D?

simonx 131 Reputation points
2024-12-16T17:04:06.37+00:00

I am using Direct2D to generate diagrams. I want to create a glow-effect around diagram boxes, using Gaussian blur. In order to do this, I paint a rectangle to an off-screen render target, blur it, and then get the off-screen render target's bitmap and call DrawImage on the normal render target to paint it back into the main window. Finally I paint the standard rectangle on top of the blurred one, and this gives a pleasing glow effect. This works fine when painting to a window. Unfortunately it doesn't work when painting to a printer. The problem is these lines of code:

CComPtr<ID2D1BitmapRenderTarget> pOffscreenRenderTarget;

HRESULT hr = pRenderTarget->CreateCompatibleRenderTarget(&pOffscreenRenderTarget);

The latter call fails. I get "DXGI_FORMAT_UNKNOWN is not allowed as a parameter to this API when the target is set to NULL or is a command list." It is true that when I print, I create a command list, and call "SetTarget" on the device context, to output to this (my render target is an ID2D1DeviceContext5). My users frequently "print" to a PDF file and you get smaller PDF files if I output to a command list.

So my question is: how can I continue to output to a command list, while also generating a Gaussian blur?

Windows development | Windows API - Win32
Developer technologies | C++
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.