Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can BASE64 encode the content of the image directly into the SRC attribute, however, I believe only Firefox will parse this back into an image.</p> <p>What I typically do is a create a very lightweight HTTPHandler to serve the images:</p> <pre><code>using System; using System.Web; namespace Example { public class GetImage : IHttpHandler { public void ProcessRequest(HttpContext context) { if (context.Request.QueryString("id") != null) { Blob = GetBlobFromDataBase(id); context.Response.Clear(); context.Response.ContentType = "image/pjpeg"; context.Response.BinaryWrite(Blob); context.Response.End(); } } public bool IsReusable { get { return false; } } } } </code></pre> <p>You can reference this directly in your img tag:</p> <pre><code>&lt;img src="GetImage.ashx?id=111"/&gt; </code></pre> <p>Or, you could even create a server control that does it for you:</p> <pre><code>using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Example.WebControl { [ToolboxData("&lt;{0}:DatabaseImage runat=server&gt;&lt;/{0}:DatabaseImage&gt;")] public class DatabaseImage : Control { public int DatabaseId { get { if (ViewState["DatabaseId" + this.ID] == null) return 0; else return ViewState["DataBaseId"]; } set { ViewState["DatabaseId" + this.ID] = value; } } protected override void RenderContents(HtmlTextWriter output) { output.Write("&lt;img src='getImage.ashx?id=" + this.DatabaseId + "'/&gt;"); base.RenderContents(output); } } } </code></pre> <p>This could be used like</p> <pre><code>&lt;cc:DatabaseImage id="db1" DatabaseId="123" runat="server/&gt; </code></pre> <p>And of course, you could set the databaseId in the codebehind as needed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload