Varmatic maximum image

I store images in a database in a field varbinary(max).

I am trying to display an image in my form. I tried many different ways, but did not show.

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 to display an image in my form?

I am using Ext.Net (Coolite).

+3
source share
2 answers

In a web application, image controls have a property ImageUrlthat points to some side of the server script that will return the image. I am not familiar with Ext.Net.Image, but I suppose you need to use the 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 specify the image control point for this common 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);
+4
source

, Ext.Net , FromStream , : System.Drawing.Image.FromStream; , , System.Drawing -. , - BLOB .

, , , MemoryStream.

+2

Source: https://habr.com/ru/post/1793361/


All Articles