我试图建立与WPF 16位PNG图像的图像浏览器。我的想法是与PngBitmapDecoder加载图像,然后把它们放到一个Image控制,并控制像素着色器的亮度/对比度。

然而,我注意到,输入到像素着色器似乎已经转换为8位。那是WPF或已知的限制没有我犯了一个错误的地方? (I检查了与我在Photoshop中创建并且被验证为16位图像的黑/白梯度图像)

这里的加载图像的代码(以确保我加载与所述完整的16位范围,只是在图像控制加载它作为8位写源=“test.png”)

BitmapSource bitmap;
using (Stream s = File.OpenRead("test.png"))
{
  PngBitmapDecoder decoder = new PngBitmapDecoder(s,BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
  bitmap = decoder.Frames[0];
}

if (bitmap.Format != PixelFormats.Rgba64)
  MessageBox.Show("Pixel format " + bitmap.Format + " is not supported. ");

bitmap.Freeze();
image.Source = bitmap;

我创建与伟大 Shazzam着色效果工具中的像素着色器。

sampler2D implicitInput : register(s0);

float MinValue : register(c0);
float MaxValue : register(c1);

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 color = tex2D(implicitInput, uv);

 float t = 1.0f / (MaxValue-MinValue);

    float4 result;    
    result.r = (color.r - MinValue) * t;
    result.g = (color.g - MinValue) * t;
    result.b = (color.b - MinValue) * t;
    result.a = color.a;

    return result;
}

和集成所述着色器到XAML这样的:

<Image Name="image" Stretch="Uniform">
  <Image.Effect>
    <shaders:AutoGenShaderEffect x:Name="MinMaxShader" Minvalue="0.0" Maxvalue="1.0>
    </shaders:AutoGenShaderEffect>
  </Image.Effect>
</Image>
有帮助吗?

解决方案

我刚刚从微软的回应。这是真正的WPF渲染系统的限制。我会尽力D3DImage作为一种解决方法。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top