在 ASP.NET 中从二进制数据转换为图像控件 [英] Convert from binary data to an image control in ASP.NET

查看:19
本文介绍了在 ASP.NET 中从二进制数据转换为图像控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一个图像的二进制数据,我想在 ASP.NET 的图像控件中显示它.如何?如果不能,请另寻方法将其保存在数据库中,并在图像控件中显示.

I have binary data of an image in my database, and I want to display it in an image control in ASP.NET. How? If it is impossible, please find another way to save it in the database and display it in an image control.

推荐答案

像这样创建一个常规的 HTML img 元素:

Create a regular HTML img element like so:

<img runat="server" id="image" />

代码隐藏中,这样做:

image.src = "data:image/png;base64," + Convert.ToBase64String(imageBytes);

其中 imageBytes 是 byte[].

Where imageBytes is a byte[].

你已经完成了.将显示图像.

You are done. The image will be displayed.

这篇关于在 ASP.NET 中从二进制数据转换为图像控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆