我會創建一個Http處理程序來執行此操作。一些瀏覽器支持在標記中寫入二進制圖像,但這是非標準的,所以我會建議不要這樣做。
如果你可以從你的查詢字節做這樣的事情:
然後創建的處理程序。
public class IISHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
myent logo = new myent();
var query = (from p in logo.tblLogoes
where p.Id == id && p.Id2 == id2
select p.Image).First();
byte[] bytes = query.bytes;
context.Response.OutputStream.Write(bytes, 0, bytes.Length);
}
}
註冊手柄:
<system.web>
<httpHandlers>
<!-- ImageHandler handlers -->
<add verb="*" path="myimages/*.jpg" type="namespace.IISHandler, namespace" />
</httpHandlers>
...
在您的網頁讓<img>
標記點的處理程序。
<img src="myimages/someimage.jpg">
你的代碼很少顯示你如何定位圖像,id的名字?很可能你想傳遞一些標識符給處理程序,所以你可以提供正確的圖像。
查看http://msdn.microsoft.com/en-us/library/ms972953.aspx,獲取有關使用http處理程序提供動態內容的更深入示例。