Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 806161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:12:03+00:00 2026-05-15T00:12:03+00:00

How can I show an image base64 encoded using WebBrowser control in C#? I

  • 0

How can I show an image base64 encoded using WebBrowser control in C#?

I used the following code:

<img src="data:image/gif;base64,/9j/4AAQSkZJRgABAgAAZABkAA7AAR
R894ADkFkb2JlAGTAAAAAAfbAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBw
...
uhWkvoJfQO2z/rf4VpL6CX0Dts/63+FaS+gl9A7bP+tthWkvoJfQODCde4qfcg
RiNWK3UyUeX9CXpHU43diOK915X5fG/reux5hUAUBftZ" />

but no image is displayed. One solution would be to save images locally and using absolute path, but this is not desirable.

Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:12:03+00:00Added an answer on May 15, 2026 at 12:12 am

    I tried doing this for a project and IE (which the WebBrowser control will eventually use) became the limiting factor – it can only hold 32Kb-sized images. I wound up having to create an HTTP handler (.ashx) that returned the image based on a database key.

    edit: example – note the database handling routines are proprietary and you’d have to put in your own. The rest of the handler will show how to rescale images (if desired) and send back as a response to the browser:

    public class GenerateImage : IHttpHandler
    {
        /// <summary>
        /// Shortcut to the database controller.  Instantiated immediately
        /// since the ProcessRequest method uses it.
        /// </summary>
        private static readonly IDataModelDatabaseController controller =
            DataModelDatabaseControllerFactory.Controller;
    
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler
        /// that implements the <see cref="T:System.Web.IHttpHandler"/>
        /// interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/>
        /// object that provides references to the intrinsic server objects
        /// (for example, Request, Response, Session, and Server) used to
        /// service HTTP requests.</param>
        public void ProcessRequest(HttpContext context)
        {
            if (controller == null)
            {
                return;
            }
    
            IDataModelDescriptor desc = controller.GetDataModelDescriptor(
                new Guid(context.Request.QueryString["dataModel"]));
            IDataModelField imageField =
                desc.Fields[context.Request.QueryString["imageField"]];
            IDatabaseSelectQuery query = controller.CreateQuery();
            string[] keys = context.Request.QueryString["key"].Split(',');
            string showThumb = context.Request.QueryString["showThumbnail"];
            bool showThumbnail = showThumb != null;
    
            query.AssignBaseTable(desc);
            query.AddColumn(imageField, false);
            for (int i = 0; i < desc.KeyFields.Count; i++)
            {
                query.AddCompareValue(
                    desc.KeyFields[i],
                    keys[i],
                    DatabaseOperator.Equal);
            }
    
            context.Response.CacheControl = "no-cache";
            context.Response.ContentType = "image/jpeg";
            context.Response.Expires = -1;
    
            byte[] originalImage = (byte[])controller.ExecuteScalar(query);
    
            if (showThumbnail)
            {
                int scalePixels;
    
                if (!int.TryParse(showThumb, out scalePixels))
                {
                    scalePixels = 100;
                }
    
                using (Stream stream = new MemoryStream(originalImage))
                using (Image img = Image.FromStream(stream))
                {
                    double multiplier;
    
                    if ((img.Width <= scalePixels)
                        && (img.Height <= scalePixels))
                    {
                        context.Response.BinaryWrite(originalImage);
                        return;
                    }
                    else if (img.Height < img.Width)
                    {
                        multiplier = (double)img.Width / (double)scalePixels;
                    }
                    else
                    {
                        multiplier = (double)img.Height / (double)scalePixels;
                    }
    
                    using (Bitmap finalImg = new Bitmap(
                        img,
                        (int)(img.Width / multiplier),
                        (int)(img.Height / multiplier)))
                    using (Graphics g = Graphics.FromImage(finalImg))
                    {
                        g.InterpolationMode =
                            InterpolationMode.HighQualityBicubic;
                        finalImg.Save(
                            context.Response.OutputStream,
                            ImageFormat.Jpeg);
                    }
                }
            }
            else
            {
                context.Response.BinaryWrite(originalImage);
            }
        }
    
        /// <summary>
        /// Gets a value indicating whether another request can use the
        /// <see cref="T:System.Web.IHttpHandler"/> instance.
        /// </summary>
        /// <value></value>
        /// <returns>true if the <see cref="T:System.Web.IHttpHandler"/>
        /// instance is reusable; otherwise, false.
        /// </returns>
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.