【发布时间】:2011-09-27 13:01:42
【问题描述】:
我需要在我的 asp.net 页面上显示一个图像,该图像在 SQL Server 中存储为图像数据类型。我正在看这篇帖子,display/retrieve image from sql database in vb.net,但是,如何在<td> 元素中显示该图像?
【问题讨论】:
标签: asp.net sql-server vb.net image
我需要在我的 asp.net 页面上显示一个图像,该图像在 SQL Server 中存储为图像数据类型。我正在看这篇帖子,display/retrieve image from sql database in vb.net,但是,如何在<td> 元素中显示该图像?
【问题讨论】:
标签: asp.net sql-server vb.net image
<td> 标签不能用于显示图像,除非您在其中放入 <img> 元素。话虽如此,这就是您在 VB.NET 中从后面的代码显示图像的方式:
在您的 aspx 页面中有这种类型的标记:
<td>
<img src="" runat="server" id="imageFromDB" />
...
您可以在后面的代码中执行此操作:
Dim imageBytes() as Byte= ... // You got the image from the db here...
//jpg is used as an example on the line below.
//You need to use the actual type i.e. gif, jpg, png, etc.
//You can do imageFromDB simply because you set runat="server" on the markup
imageFromDB.src = String.Format("data:image/{0};base64,
{1}","jpg",Convert.ToBase64String(imageBytes)
这将在页面上呈现您的图像。
我希望我在这里给了你足够的信息。
【讨论】:
参考您提到的答案中的示例:
<td><img src="PathToYourHttpHandler?id=ID_OF_YOUR_IMAGE" /></td>
【讨论】: