以下に示すプロパティの結果に Image.Source プロパティをバインドしています。
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のバグかどうかは誰にも分かりますか? または私は何か間違ったことをしていますか?