我正在将 Image.Source 属性绑定到下面展示的属性的结果。
由于某种原因,在渲染图像时出现了错误(在PresentationCore程序集的深处)。我确定图像没有损坏,因为我可以成功地显示相同的图像而不使用绑定。
public BitmapSource MyImageSource
{
get
{
BitmapSource source = null;
PngBitmapDecoder decoder;
using (var stream = new FileStream(@"C:\Temp\logo.png", FileMode.Open, FileAccess.Read, FileShare.Read))
{
decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
if (decoder.Frames != null && decoder.Frames.Count > 0)
source = decoder.Frames[0];
}
return source;
}
}
由于某种原因,在渲染图像时出现了错误(在PresentationCore程序集的深处)。我确定图像没有损坏,因为我可以成功地显示相同的图像而不使用绑定。
<Image Name="FooImage" Source="/logo.png" />
我需要在代码中绑定图像源,因为最终我将从base64字符串创建图像流。
有人知道这是WPF的错误吗?还是我做错了什么?