c# - C# 中的 Image 类在哪里?
问题描述
我只是想对位图图像进行编码和解码,但 Image 类显然不存在。我要离开这个页面来创建一个解码器。我在
Image drawnImg = new Image();
它说,“找不到类型或命名空间”,我使用的每个导入都没有修复这个错误。我在这里想念什么图书馆?
这是代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using System.Drawing;
namespace Thompson_BmpDecodeEncode
{
class Thompson_BmpDecodeEndoce
{
static void Main(string[] args)
{
Uri img = new Uri("<FilePath to image.bmp>", UriKind.RelativeOrAbsolute);
BmpBitmapDecoder decoder2 = new BmpBitmapDecoder(img,
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource2 = decoder2.Frames[0];
Image drawnImg = new Image();
Console.ReadKey();
}
}
}
解决方案
当我找不到库时,我喜欢做的一件事是打开我最喜欢的搜索引擎并搜索它(添加 c# 也无妨)。
搜索“c# image class”时的最高结果是:Image Class,其中指出:
命名空间:
System.Drawing
更新:
此外,为了using
为库添加语句,您需要首先在项目中添加对该库的引用。要在 Visual Studio 中执行此操作,您可以右键单击References
项目下的节点Solution Explorer
,然后在 下Assemblies -> Framework
,您可以选中旁边的框System.Drawing
:
如果您不使用 Visual Studio,则可以.csproj
使用参考编辑文件:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="" DefaultTargets="" xmlns="">
<ItemGroup>
<Reference Include="System.Drawing" />
推荐阅读
- git - 詹金斯:颤振酒吧获取,在PATH中找不到git
- powershell - 外部脚本未在 JEA PowerShell 中运行
- c# - 如何在 2 个 C# 类之间共享字符串
- bash - 以十六进制保存接下来的 32 个字节(搜索后)
- typescript - 在打字稿类中导入 p5
- java - 当 Java 进程被 OOM reaper 杀死时生成内存转储
- jpa - 使用 EmbeddedID 创建新的 JPA 实体
- javascript - 应用 JS 功能后“按钮”缩小
- javascript - 无法创建 Vue 应用程序 http-server - 错误:css 和 js 文件 404 未找到
- javascript - 为什么当我滚动到顶部然后在我的 API 应用程序上返回但在网页上正常运行时,我的页面顶部按钮口吃/滞后/粘住?