WPF图像和DirectX SurfaceFormat图像、WPF、SurfaceFormat、DirectX

2023-09-03 01:12:12 作者:帝王之战

我有我想要显示在.NET 3.5 SP1使用WPF一个16位的灰度图像。目前,I,采用使用OpenGL到图像显示格式设置为亮度16嵌入的winform显示该图像。

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也有类似的性质, SurfaceFormat 。

DirectX has a similar property, SurfaceFormat.

我希望能够显示在WPF中的图像,并设置SurfaceFormat为Luminance16。我该怎么办呢?

I want to be able to display an image in WPF and set the SurfaceFormat to Luminance16. How do I do that?

注:目前,尽管WPF本身支持Gray16,它不会使Gray16正确

Note: Currently, even though WPF natively supports Gray16, it doesn't render Gray16 properly.

编辑:真正的答案是,WPF中没有做什么它认为它。 Gray16,同时本机支持,实际上是256,以适应16位显示分。因此,Gray16格式是一个谎言,嫉恨如酸的眼睛。

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.

推荐答案

您应该不需要做这在WPF。

You shouldn't need to do this in WPF.

WPF支持 16bpp的灰度图像本身。我相信他们可以使用一个TIF文件中加载内置的TIFF格式德codeR。

WPF supports 16bpp grayscale images natively. I believe they can be loaded from a TIF file using the built in TIFF format decoder.

编辑的效应初探评论:

如果你不快乐与WPF中的默认渲染,你也可以使用DirectX直接呈现在表面。这是(thusfar)最好使用C ++ / CLI,但它有可能完全在C#中使用SlimDX。

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.

最好的办法无非是要使用 D3DImage 。有一个介绍到 $ C $的CProject 用这个。你应该能够端口的OpenGL $ C $横跨pretty的ç直接得多,考虑到DX的差异。关于D3DImage的好处,不过,是你不再需要主机通用的控制 - 你可以直接把这个变成一个WPF画笔,并用它在任何地方WPF

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.