加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 01:51:35 所属栏目:百科 来源:网络整理
导读:我正在尝试将Base64String转换回 Image.我在我的C#控制台应用程序中设置了此代码. public Image Base64ToImage(string base64String){ // Convert Base64 String to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); MemoryStream ms =
我正在尝试将Base64String转换回 Image.我在我的C#控制台应用程序中设置了此代码.

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

    // Convert byte[] to Image
    ms.Write(imageBytes,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的程序集.只需添加程序集引用,它应该没问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读