tags:

views:

257

answers:

2

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.

+2  A: 

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.

Reed Copsey
yeah, but in reality, I do. The native support is causing the images to dither exactly as if they were being displayed as 8 bit luminance images in OpenGl.
mmr
@mmr: I edited my answer with more info.
Reed Copsey
@Reed-- I was hoping to avoid the d3d, but hey, it does remove the winforms encapsulation. I'll check it out.
mmr
Any performance issues using D3DImage + SlimDX or whatever solution you ended up using? How long does rendering one frame take?
Danny Varod
Using D3DImage + SlimDX is very, very fast... SlimDX is a great solution, and I've done that quite well. I personally have my DX rendering tied to the Dispatcher's present timer, so it happens about 60-65 FPS (the same as the WPF UI, at the same time). For an image processor, you could do it as fast as you want, but there's no real reason to go faster than your monitor's refresh.
Reed Copsey
A: 
Danny Varod
Ah, but the screens I'm displaying on are 11 bit ACR accredited mammography screens. So, the 8 bit compression is not only wrong, it's potentially life threatening if a doctor can't see the cancer they should be able to see. Also, for the record, division by 256 assumes a full 16 bit range, which is rarely the case in most imaging. Only recent medium format backs have put out 16 bit images, usually it's 12 or 14.
mmr
In that case you should add a histogram-based 16 to 11 bit compression to the high dynamic range display solution you were given. (Otherwise you are dividing by 32.)
Danny Varod