我遇到了以下编译时错误:
找不到类型或命名空间名称“Bitmap”(您是否缺少使用指令或程序集引用?)
这是我的代码:
BitmapImage img = new BitmapImage();
您需要将 System.Drawing
添加到引用中,因此在解决方案资源管理器中右键单击“ 引用 ”,然后单击“添加引用”,在程序集中找到System.Drawing
并单击OK
今天(2020年)的NuGet包是System.Drawing.Common.dll
。
添加方法:在项目名称上单击右键(在解决方案资源管理器中)--> "管理NuGet程序包" --> 在顶部选择“浏览”标签 --> 搜索“System.Drawing.Common” --> 安装。
添加PresentationCore作为引用。
PresentationCore程序集将出现在您的项目引用列表中。
在文件顶部添加System.Windows.Media.Imaging命名空间的using指令,这是BitmapImage
所在的位置。
using System;
using System.Windows.Media.Imaging;
Bitmap
而不是BitmapImage
。 - tomfanningusing System.Windows.Media.Imaging;
System.Drawing
。 - Alvin WongSystem.Drawing
是不正确的 - BitmapImage
在 System.Windows.Media.Imaging
命名空间中,并且在 PresentationCore.dll
中,该文件应该在 .NET 3 及更高版本的 GAC 中。 - tomfanning