将base64string转换为Image类型.找不到图片类型?

Bea*_*iew 3 c# base64 types image type-conversion

我正试图将一个Base64String回归到一个Image.我在我的C#控制台应用程序中设置了此代码.

public Image Base64ToImage(string base64String)
{
    // Convert Base64 String to byte[]
    byte[] imageBytes = Convert.FromBase64String(base64String);
    MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

    // Convert byte[] to Image
    ms.Write(imageBytes, 0, imageBytes.Length);
    Image image = Image.FromStream(ms, true);
    return image;
}
Run Code Online (Sandbox Code Playgroud)

我每次使用该类型时都会收到错误Image.它说:

找不到类型或命名空间名称.

我正在使用:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Net.Mime;
using System.Drawing;
Run Code Online (Sandbox Code Playgroud)

我错过了一个图书馆吗?

Jon*_*eet 6

是的,如果您正在编写控制台应用程序,您的项目可能不会包含对System.Drawing.dll包含的程序集的引用System.Drawing.Image.只需添加程序集引用,它应该没问题.