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

simonx 126 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 API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,717 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,834 questions
{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.