我正在尝试将 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/