0

我正在尝试使用 WriteableBitmapEx 从硬盘驱动器上的图像创建 WriteableBitmap。添加nuget包后,我从官方页面复制了代码:

WriteableBitmap writeableBmp = new WriteableBitmap(0, 0).FromResource("Data/flower2.png");

但我得到了错误

'System.Windows.Media.Imaging.WriteableBitmap' 不包含采用 2 个参数的构造函数

我已经添加了 PresentationCore.dll,正如我在控制台应用程序中的 WriteableBitmapEx 被告知的那样? 以及 System.Windows.Media.Imaging 的 using 语句。

4

1 回答 1

5

WriteableBitmapEx库为构造可写位图提供了一个通用工厂方法,即BitmapFactory.New. 改用这个可移植的方法来生成你的虚拟可写位图:

WriteableBitmap writeableBmp = BitmapFactory.New(0, 0).FromResource("Data/flower2.png");

该类BitmapFactory位于System.Windows.Media.Imaging命名空间中(除非您使用的是 WinRT 版本的WriteableBitmapEx,它位于Windows.UI.Xaml.Media.Imaging命名空间中)。

于 2013-03-10T09:20:10.303 回答