Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#winforms中引用图像类?_C# - Fatal编程技术网

如何在C#winforms中引用图像类?

如何在C#winforms中引用图像类?,c#,C#,我正在做一个新项目,这是一个类库 我的问题是我总是会犯这样的错误: The type or namespace name 'Drawing' does not exist in the namespace 'System' (are you missing an assembly reference?) 这是我的代码: using System; using System.Collections.Generic; using System.Linq; using System.Text;

我正在做一个新项目,这是一个类库

我的问题是我总是会犯这样的错误:

The type or namespace name 'Drawing' 
does not exist in the namespace 'System' (are you missing an assembly reference?)
这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace ClassLibrary1
{
    public class Class1
    {
        public void ReturnImage(object imageStream)
        {
            try
            {
                byte[] data = (byte[])imageStream;
                MemoryStream ms = new MemoryStream(data);
                return Image.FromStream(ms);
            }
            catch
            {
            }
        }
    }
}
我计划使用这个类作为我将在程序中重用的常用方法的存储库。在上面的代码中,我有一个公共方法
ReturnImage
,它应该会接受一个对象并返回一个
Image


但我为什么会犯这样的错误呢?请帮助…

添加对System.Drawing的引用

从VS菜单:项目>添加引用

为了避免您不停地键入:
,请使用namespacehere

Ctrl+。
(控件和。),它将使用名称空间在此处自动插入
基于您使用的类在代码之上。例如,将光标放在
Image.FromStream
Image
内的任何字符上,然后按
Ctrl+。
,它将使用System.Drawing自动插入
在您的代码之上。同样,在
Image的
FromStream
上执行相同操作(按
Ctrl+。
),FromStream
,它将使用System.IO自动插入
在您的代码之上