2010-09-21 36 views
0

有這樣的事嗎?!快速查詢以檢索圖像加載的二進制圖像?

因此,例如,在我的圖像加載我有以下連接到一個表「圖像」是一個二進制圖像數據集。

protected void Image1_Load1(object sender, EventArgs e) 
    { 
     myent logo = new myent(); 

     var query = (from p in logo.tblLogoes 
        where p.Id == id && p.Id2 == id2 
        select p.Image).First(); 

     return query. 
    } 

我需要在這裏返回來填充圖像?

我有趣的感覺,它不會那麼簡單!

任何指針感激地收到。

回答

0

我會創建一個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處理程序提供動態內容的更深入示例。