WriteableBitmap使程序崩溃而没有消息? [英] WriteableBitmap crashes program with no message?

查看:194
本文介绍了WriteableBitmap使程序崩溃而没有消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个WriteableBitmap对象,画一条线,然后尝试将其设置为Image控件的源.由于某种原因,该程序停止响应,然后在5秒钟后尝试设置Source时关闭.有人知道怎么了吗? (我也在使用WriteableBitmapEx)

I create a WriteableBitmap object, draw a line and try to set it as the source to an Image control. For some reason, the program stops responding and then closes 5 seconds later when I try to set the Source. Anyone have any idea what's wrong? (I am also using WriteableBitmapEx)

WriteableBitmap bit = new WriteableBitmap(400, 400, 96, 96, PixelFormats.Bgr32, null);
WriteableBitmapExtensions.DrawLine(bit, 10, 10, 300, 300, Core.PrimaryColor.ColorValue);
ImageCanvas.Source = bit; // Sets the image to our bitmap, but program crashes for some reason!

推荐答案

当我尝试您的代码时,它会抛出ArgumentException说

When I try your code, it throws an ArgumentException saying

输入的WriteableBitmap必须具有Pbgra32像素格式.使用 BitmapFactory.ConvertToPbgra32Format方法自动 将任何输入的BitmapSource转换为此格式接受的正确格式 类.\ r \ n参数名称:writeableBitmap

The input WriteableBitmap needs to have the Pbgra32 pixel format. Use the BitmapFactory.ConvertToPbgra32Format method to automatically convert any input BitmapSource to the right format accepted by this class.\r\nParametername: writeableBitmap

因此,它起作用:

var bitmap = new WriteableBitmap(400, 400, 96, 96, PixelFormats.Pbgra32, null);
WriteableBitmapExtensions.DrawLine(bitmap, 10, 10, 300, 300, Colors.Black);
image.Source = bitmap;

更新:如Anders所述,您也许应该使用WriteableBitmapEx提供的可移植位图工厂方法来创建位图:

UPDATE: As noted by Anders, you should perhaps use the portable bitmap factory method provided by WriteableBitmapEx to create your bitmap:

var bitmap = BitmapFactory.New(400, 400);
WriteableBitmapExtensions.DrawLine(bitmap, 10, 10, 300, 300, Colors.Black);
image.Source = bitmap;

这篇关于WriteableBitmap使程序崩溃而没有消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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