Reputation: 14929
I have a 16 bit grayscale image that I want to display using WPF in .NET 3.5 sp1. Currently, I display that image using an embedded winform that uses OpenGL to set the image display format to Luminance 16.
DirectX has a similar property, SurfaceFormat.
I want to be able to display an image in WPF and set the SurfaceFormat to Luminance16. How do I do that?
Note: Currently, even though WPF natively supports Gray16, it doesn't render Gray16 properly.
Edit: The real answer is that WPF does not do what it says it does. Gray16, while supported natively, is actually divided by 256 in order to fit into a 16 bit display. So, the Gray16 format is a lie that burns like acid in the eyes.
Upvotes: 4
Views: 2933
Reputation: 18118
WPF isn't the real issue - most screens do not support 16bit output, therefore you need to compress the 16bit of gray levels to 8bit.
This can be done by dividing by 256 or by using a histogram based algorithm for diving the 2^16 gray level into 256 bins in another manner.
For this, image processing is required and there are many articles on different approaches (search for displaying high dynamic range images). You could use HLSL shaders to help.
Upvotes: 0
Reputation: 564771
You shouldn't need to do this in WPF.
WPF supports 16bpp grayscale images natively. I believe they can be loaded from a TIF file using the built in TIFF format decoder.
Edit in reponse to comment:
If you're unhappy with the default rendering in WPF, you can also use DirectX to directly render the surface. This is (thusfar) best done using C++/CLI, but it is possible entirely in C# using SlimDX.
The best approach out there is to use D3DImage. There's an intro to using this on CodeProject. You should be able to port your OpenGL code across pretty much directly, taking into account the differences in DX. The nice thing about D3DImage, though, is that you no longer need to host a common control - you can put this directly into a WPF Brush and use it anywhere in WPF.
Upvotes: 2