首页 > 解决方案 > 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#bitmap

解决方案


当我找不到库时,我喜欢做的一件事是打开我最喜欢的搜索引擎并搜索它(添加 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" />

推荐阅读