Dynamically create thumbnail from full size jpg image stored as database blob (VarBinary(Max)) RRS feed

  • Question

  • User-596903714 posted

    Hi I am building a web front end for a database that I have inherited and need to display jpegs associated with a customer orders.  Unfortunately, the original programmer stores up to 20 hi-res images as blobs in the database that need to be viewed on a web page with the order.  Is it possible to dynamically create a thumbnail version of the image on the fly as the page is loaded instead of loading the full size images.  Ideally, I need a free solution, I looked at ImageResizer but it costs $1200 per year.


    Tuesday, August 22, 2017 4:28 PM

All replies

  • User-943250815 posted

    Look for ImageProcessor in Nuget

    Tuesday, August 22, 2017 11:51 PM
  • User347430248 posted

    Hi PhillD,

    you can try to use Image.GetThumbnailImage Method from System.drawing.


    <form id="form1" runat="server">
    <asp:Image ID="Image1" runat="server" ImageUrl = "~/Jellyfish.jpg" Height = "400px" Width = "400px"/>
    <br />
    <asp:Button ID="btnGenerate" OnClick = "GenerateThumbnail" runat="server" Text="Generate Thumbnail" />
    <hr />
    <asp:Image ID="Image2" runat="server" Visible = "false"/>
    using System.IO;
    using System.Drawing;
    using System.Drawing.Imaging;
    protected void GenerateThumbnail(object sender, EventArgs e)
        string path = Server.MapPath("~/Jellyfish.jpg");
        System.Drawing.Image image = System.Drawing.Image.FromFile(path);
        using (System.Drawing.Image thumbnail = image.GetThumbnailImage(100, 100, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero))
            using (MemoryStream memoryStream = new MemoryStream())
                thumbnail.Save(memoryStream, ImageFormat.Png);
                Byte[] bytes = new Byte[memoryStream.Length];
                memoryStream.Position = 0;
                memoryStream.Read(bytes, 0, (int)bytes.Length);
                string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
                Image2.ImageUrl = "data:image/png;base64," + base64String;
                Image2.Visible = true;
    public bool ThumbnailCallback()
        return false;



    Dynamically generate and display Thumbnail picture by resizing the Image in ASP.Net

    Image.GetThumbnailImage Method



    Wednesday, August 23, 2017 6:37 AM
  • User-596903714 posted

    Thank you for this.  The only thing it looks like I need to change is feeding blob into the code instead of a file path.

    Wednesday, August 23, 2017 1:03 PM