3

我正在尝试使用 WPF 为 16 位 PNG 图像构建图像查看器。我的想法是用 加载图像PngBitmapDecoder,然后将它们放入Image控件中,并使用像素着色器控制亮度/对比度。

但是,我注意到像素着色器的输入似乎已经转换为 8 位。这是 WPF 的已知限制还是我在某处犯了错误?(我用我在 Photoshop 中创建的黑白渐变图像进行了检查,该图像被验证为 16 位图像)

这是加载图像的代码(以确保我加载完整的 16 位范围,只需在 Image 控件中写入 Source="test.png" 将其加载为 8 位)

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>
4

1 回答 1

2

我刚收到微软的回复。这确实是 WPF 渲染系统的一个限制。我会尝试D3DImage作为一种解决方法。

于 2009-10-13T14:41:40.203 回答