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

如何动态显示asp.net页面上的字节图像?

发布时间:2020-12-16 10:01:55 所属栏目:asp.Net 来源:网络整理
导读:我已经从Web服务加载了一个字节数组图像到我的asp.net网站. 我需要在执行Web服务后立即在网页上显示它. 我尝试过使用泛型处理程序,但我无法做到,因为无法将byte []图像传递给泛型处理程序 void Button2_Click1(object sender,EventArgs e){ this.verifyTempl
我已经从Web服务加载了一个字节数组图像到我的asp.net网站.
我需要在执行Web服务后立即在网页上显示它.

我尝试过使用泛型处理程序,但我无法做到,因为无法将byte []图像传递给泛型处理程序

void Button2_Click1(object sender,EventArgs e)
{

    this.verifyTemplates();
    byte[] userImg;
    try
    {

        matchTemp.templateService hs = new matchTemp.templateService();
        bool s1 = hs.matchTemplates(template,out userID,out userName,out userImg);
// userImg is the byte image i need to display

    }
    catch(Exception exc)
    {
     //   vLabel.Text = exc.Message;
    }
}

解决方法

你要找的是 Data URL.你可以得到像这样的字节数组的base64(根据需要改变图像类型)

string imageBase64 = Convert.ToBase64String(userImg);
string imageSrc = string.Format("data:image/gif;base64,{0}",imageBase64);

在视图中:

<img src='"<%=imageSrc%>"' />

这在IE 7或更早版本中无效,如果您需要支持那些,那么您将需要查看MHTML.

(编辑:李大同)

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

    推荐文章
      热点阅读