从控制台应用程序中的资源创建WriteableBitmap

Tho*_*mas 0 c# console-application writeablebitmap writeablebitmapex

我正在尝试使用WriteableBitmapEx从我的硬盘驱动器上的Image创建一个WriteableBitmap.我在添加nuget包后复制了官方页面中的代码:

WriteableBitmap writeableBmp = new WriteableBitmap(0, 0).FromResource("Data/flower2.png");
Run Code Online (Sandbox Code Playgroud)

但我得到了错误

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

我添加了PresentationCore.dll,因为我在控制台应用程序中被告知WriteableBitmapEx? 以及System.Windows.Media.Imaging的using语句.

And*_*son 5

WriteableBitmapEx库提供用于构建可写的位图,即通用的工厂方法BitmapFactory.New.使用此可移植方法来生成虚拟可写位图:

WriteableBitmap writeableBmp = BitmapFactory.New(0, 0).FromResource("Data/flower2.png");
Run Code Online (Sandbox Code Playgroud)

BitmapFactory班是在System.Windows.Media.Imaging命名空间(除非您使用的WinRT的版本WriteableBitmapEx,它是在Windows.UI.Xaml.Media.Imaging命名空间).