Question

Is it possible to use DirectX pixel shaders to create image effects for photos? I have a C++ application which includes kind of a photo database manager. It utilizes GDI+ for image processing and I want to offer the user some fancy image effects - which I would like to do via DirectX pixel shaders. I would like to achieve similar effects like the Shazzam Tool delivers out of the box with its example library - unfortunately I'm using pure GDI+ and no WPF.

For creating image effects in a GDI+ bitmap I thought of the following steps:

1) Load image via GDI+

2) Init DirectX, load/compile shader, convert GDI+ image to be used as texture in DirectX

3) Draw 4 vertices in DirectX and use the photo as texture

4) Apply the pixel shader

5) Save the surface with the pixel shadered photo

1-4 is already solved, but how do I achieve step 5?

Currently I'm using the following snippet for gathering the modified photo:

d3dDevice->GetRenderTarget(0, &surface);

D3DXSaveSurfaceToFile("Test.png", D3DXIFF_PNG, surface, NULL, NULL);

surface->Release();
surface = NULL;

This code doesn't fit my needs, since it captures the whole scene and not only the texture (=photo). How can I achieve to getting the pixel shadered photo texture in its original size back? I would like to achieve the same result as Shazzam Tool delivers, but without WPF...

Thank you in advance!

Cheers!

Was it helpful?

Solution

I'd simply create a offscreen render target (render to texture) with the proper dimensions and save that one as a surface (like you do already). Rendering to the visible screen space (sounds like you're doing that right now) is definitely something you'd most likely try to avoid. If you'd like to display the result as well, render the rendered texture.

OTHER TIPS

This is old question, but bow there are Direct2D effects that do what you want.

https://docs.microsoft.com/en-us/windows/win32/direct2d/built-in-effects

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top