Jag*_*agd 1 c# asp.net memorystream image
我有一些图像(主要是png和jpg),我存储在SQL Server 2008的FileStream中.我能够检索所述图像并将它们存储在MemoryStream中.
我有一个网页,我需要在MemoryStream中显示图像.有没有什么方法可以在HTML图像标记内显示MemoryStream的内容(甚至更好,在ASP.NET图像控件中)?
Jas*_*ley 10
是,
HTML
<img src="loadimage.ashx?id=..."/>
Run Code Online (Sandbox Code Playgroud)
为项目和loadimage处理程序添加一个通用的处理程序
class loadimage: ihttphandler
{
public void Process(HttpContext context)
{
var id = context.Request["id"];
var row = GetImageFromDb(id);
var response = context.Response;
response.AddHeader("content-disposition", "attachment; filename=" + row["anem of image"]);
response.ContentType = row["mime type"].ToString(); //png or gif etc.
response.BinaryWrite((byte[])row["image blob"]);
}
public bool Reuse { get {return true; } }
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9983 次 |
最近记录: |