簡體   English   中英

Varbinary最大圖像

[英]Varbinary max image

我在varbinary(max)字段中將圖像存儲在數據庫中。

我試着在我的表格上顯示一個圖像。 我嘗試了很多不同的方法,但沒有表現出來。

這是我的代碼:

//I am adding an image in my form
Ext.Net.Image image = new Ext.Net.Image();
image.ID = "imgShow";

FormLayout1.Items.Add(image);

byte[] buffer = q.TckLogo;
MemoryStream memStream = new MemoryStream();
memStream.Write(buffer, 0, buffer.Length);

// it is giving error because of FromStream
image.items.Add(Image.FromStream(memStream)); 

如何在表單中顯示圖像?

我正在使用Ext.Net(Coolite)。

在Web應用程序中,圖像控件具有指向某些服務器端腳本的ImageUrl屬性,該腳本將返回圖像。 我不熟悉Ext.Net.Image但我想你需要使用http處理程序來提供圖像:

public class ImageHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var id = context.Request["id"];
        byte[] imageData = FetchImageFromDb(id);
        context.Response.ContentType = "image/png";
        context.Response.OutputStream.Write(imageData, 0, imageData.Length);
    }

    public bool IsReusable
    {
        get { return true; }
    }
}

然后讓你的圖像控制指向這個通用處理程序:

Ext.Net.Image image = new Ext.Net.Image();
image.ID = "imgShow";
// pass some id to the generic handler which will 
// allow it to fetch the image from the database
// and stream it to the response
image.ImageUrl = "~/ImageHandler.ashx?id=123"; 
FormLayout1.Items.Add(image);
image.items.Add(image);

我不清楚Ext.Net在這里是什么,或者你為什么使用它,但FromStream用法表明你很困惑的是System.Drawing.Image.FromStream ; 但是,事件沒有實際意義,因為您不應該使用 Web應用程序中的System.Drawing。 如果你只是想將圖像返回給客戶端,你不應該在所有處理它在許多情況下-只是扔BLOB沿着電線到客戶端。

不相關,但Jon注意到你也試圖從MemoryStream的末尾讀取。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM