我必须使用绘制位图图像绘图上下文.DrawImage http://msdn.microsoft.com/en-us/library/ms606804%28v=vs.90%29.aspx method.
使用下面的代码一切正常:
BitmapImage myImage = new BitmapImage();
myImage.BeginInit();
myImage.UriSource = new Uri("image.png", UriKind.Relative);
myImage.EndInit();
Rect area = new Rect(new Size(myImage.PixelWidth, myImage.PixelHeight));
DrawingVisual myVisual = new DrawingVisual();
using (DrawingContext context = myVisual.RenderOpen())
{ context.DrawImage(myImage, area); }
但前提是图像不超过 2Mb 左右,即面积 (myImage.PixelWidth x myImage.PixelHeight
) 不大于 10000x10000。在这种情况下,屏幕保持空白,并且不会引发任何异常(因此我无法判断是否存在错误)。
我该如何解决这个问题?
谢谢。
渲染时似乎尚未加载较大的图像。尝试以下方法加载位图:
BitmapSource myImage = BitmapFrame.Create(
new Uri("image.png"),
BitmapCreateOptions.None,
BitmapCacheOption.OnLoad);
或者这种绝望的尝试:
using (Stream fileStream = new FileStream("image.png", FileMode.Open))
{
BitmapSource myImage = BitmapFrame.Create(
fileStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)