我的程序中在后台生成bitmapimage,并以此创造imagebrush。代码如下:
public static BitmapImage GetBitmapImage(string filePath)
{
byte[] bytes = File.ReadAllBytes(filePath);
// Init bitmap
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = new MemoryStream(bytes);
//if (File.Exists(filePath))
//{
// bitmap.UriSource = new Uri(filePath, UriKind.Relative);
//}
bitmap.EndInit();
return bitmap;
}
但程序会对有些图片渲染出错,例如:
原图
渲染效果:
但如果我将图片的字节数据传到远端,用同样方法生成bitmapimage则不会出现此渲染问题。
请问如何解决(程序特殊需求决定我并不能使用UriSource进行渲染)