c# - 将 base64string 转换为 Image 类型。找不到图像类型?

标签 c# image types base64 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;
}

每次使用 Image 类型时,我都会收到错误消息。它说:

The type or namespace name could not be found.

我正在使用:

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;

我错过图书馆了吗?

最佳答案

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

关于c# - 将 base64string 转换为 Image 类型。找不到图像类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13636430/

相关文章:

c# - 带有分组项目的 ListView - 通过组标题复选框选择所有组成员

jquery - 如果页面 h1 包含特定单词,则显示特定图像?

java - 提取图像中最常用的颜色及其百分比

Haskell:如何停止向左或向右打印程序

c# - 重载转换运算符时什么时候使用关键字 "implicit"或 "explicit"?

c# - WebClient.DownloadString 给出第一次机会异常

javascript - 使用 FileReader 循环 <input multiple> 仅显示 div 网格中的最后一个图像

javascript - 没有类型的cshtml脚本标签

go - 为什么golang自定义错误变量有多种类型

c# - 获取所有用户的特定声明?