可变二进制最大图像

发布于 2024-10-18 04:03:09 字数 529 浏览 3 评论 0原文

我将图像存储在数据库的 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)。

I am storing images in database in a varbinary(max) field.

I am try to show an image on my form. I've tried many different ways but it did not show it.

This is my Code:

//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)); 

How can I display my image in my form?

I am using Ext.Net (Coolite).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明天过后 2024-10-25 04:03:09

在 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);

In a web application, image controls have an ImageUrl property pointing to some server side script which will return the image. I am not familiar with Ext.Net.Image but I suppose that you need to use a http handler to serve the image:

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; }
    }
}

and then have your image control point to this generic handler:

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);
自由如风 2024-10-25 04:03:09

我不清楚 Ext.Net 是什么,或者您为什么使用它,但 FromStream 用法表明您对 System.Drawing.Image.FromStream;但是,该事件没有实际意义,因为您不应使用 Web 应用程序中的 System.Drawing。如果您只是尝试将图像返回给客户端,那么在许多情况下您根本不需要处理它 - 只需将 BLOB 通过网络发送给客户端即可。

不相关,但正如 Jon 指出的那样,您还尝试从 MemoryStream 的末尾读取。

It isn't clear to me what Ext.Net is here, or why you are using it, but the FromStream usage suggests you are confusing is with System.Drawing.Image.FromStream; however, event that is moot as you shouldn't use System.Drawing from a web app. If you are just trying to return an image to the client, you shouldn't have to process it at all in many cases - just throw the BLOB down the wire to the client.

Unrelated, but as Jon notes you're also trying to read from the end of a MemoryStream.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文