如何在informix数据库中读取存储为byte的图像?

时间:2012-02-16 10:34:16

标签: c# asp.net image handler informix

我以字节数据类型存储在数据库中的图像。我得到如下字节数组:

Stream photo_stream = Photo_DAL.RetrievePhoto(int.Parse(reg);
byte[] photo_bytes = Photo_DAL.StreamToByteArray(photo_stream);

但我不知道如何制作imageurl =“some url”??

我搜索并找到一些关于处理程序的文章,但实际上我不知道如何使用它。请问如何通过一些解释阅读这样的图像?

1 个答案:

答案 0 :(得分:1)

  

我搜索并找到一些关于处理程序的文章,但实际上我不知道如何使用它

您可以在页面中添加通用处理程序(MyImage.ashx):

public class MyImage : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string imageId = context.Request["imageId"];
        // use the image id to fetch the photo bytes from the backend
        byte[] photoBytes = ...
        // ensure the content type matches the one of your image
        context.Response.ContentType = "image/png";
        context.Response.BinaryWrite(photoBytes);
    }

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

然后在某个Web表单中,您可以将ImageUrl控件的Image属性指向通用处理程序,并将图像的id作为查询字符串参数传递:

<asp:Image ID="myimage" runat="server" ImageUrl="~/myimage.ashx?imageid=123" />
相关问题