【问题标题】:'Bitmap' could not be found (are you missing a using directive or an assembly reference?)找不到“位图”(您是否缺少 using 指令或程序集引用?)
【发布时间】:2012-07-21 09:05:21
【问题描述】:

我收到以下编译时错误:

The type or namespace name 'Bitmap' could not be found (are you missing a using directive or an assembly reference?)

这是我的代码:

BitmapImage img = new BitmapImage();

【问题讨论】:

    标签: c# bitmap


    【解决方案1】:

    今天(2020 年)它是 nuGet 包System.Drawing.Common.dll。 添加它:右键单击项目名称(在解决方案资源管理器中)->“管理 NuGet 包”-> 选择顶部的“浏览”标签--> 搜索“System.Drawing.Common”-> 安装它.

    【讨论】:

      【解决方案2】:

      您必须将System.Drawing 添加到您的引用中,以便在解决方案中 Explorer 右键单击​​ References 并单击 Add References 并在 程序集找到System.Drawing 并单击确定

      【讨论】:

      • 应该设置为最佳答案,至少对我来说是这样。
      • 什么时候会自动发生,什么时候需要手动执行?为什么需要这样做?
      【解决方案3】:

      添加 PresentationCore 作为参考。

      操作方法:

      1. 单击 .NET 选项卡。
      2. 从列表中找到并单击 PresentationCore 项。
      3. 点击确定按钮。

      结果:

      PresentationCore 程序集出现在您项目的引用列表中。

      最后:

      在文件顶部为 System.Windows.Media.Imaging 命名空间添加 using 指令,这是 BitmapImage 所在的位置。

      using System;
      using System.Windows.Media.Imaging;
      

      【讨论】:

      【解决方案4】:

      也许你需要补充:

      using System.Windows.Media.Imaging;
      

      【讨论】:

      • 比较合适的是System.Drawing
      • 也许不是尝试自己添加库名称(在顶部,带有“使用”),而是尝试添加对库的实际引用。即添加对“System.Drawing”的引用
      • @DaneBalia 我已经做到了。手动添加参考。但它仍然无法正常工作。我不是在开玩笑。还有其他原因吗?
      • 不,如果这个基本功能不起作用,就会出现严重的问题。您是否也遇到这两个库的问题?您正在运行什么版本的 Visual Studio?什么版本的 Windows?您可能没有损坏的 VS 安装?
      • System.Drawing 不正确 - BitmapImage 位于 System.Windows.Media.Imaging 命名空间中,并且位于 PresentationCore.dll 中,该名称应位于 .NET 3 及更高版本的 GAC 中。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-18
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      相关资源
      最近更新 更多