使用的DrawImage方法黑屏 [英] Blank screen using DrawImage method

查看:439
本文介绍了使用的DrawImage方法黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要画使用位图图像 DrawingContext.DrawImage 方法。

I have to draw a bitmap image using DrawingContext.DrawImage method.

使用下面的一切code正常工作:

Using the code below everything is working correctly:

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大。在这种情况下,屏幕将保持空白,没有任何异常被抛出(所以我不能告诉你有一个错误)。

But only if the image does not exceed 2Mb about, i.e. the area (myImage.PixelWidth x myImage.PixelHeight) is not larger than 10000x10000. In this case the screen remains blank and no any exception is thrown (so I can not tell if there was an error).

我怎么能解决这个问题? 谢谢你。

How could I fix this problem? Thanks.

推荐答案

看起来就像当你使它们尚未加载较大的图像。请尝试以下方法加载位图:

Looks like larger images aren't yet loaded when you render them. Try the following to load the bitmap:

BitmapSource myImage = BitmapFrame.Create(
    new Uri("image.png"),
    BitmapCreateOptions.None,
    BitmapCacheOption.OnLoad);

或者这样绝望的尝试:

Or this desperate attempt:

using (Stream fileStream = new FileStream("image.png", FileMode.Open))
{
    BitmapSource myImage = BitmapFrame.Create(
        fileStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
}

这篇关于使用的DrawImage方法黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆