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

  • SEARCH
  • Home
  • 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 6964653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:57:06+00:00 2026-05-27T15:57:06+00:00

I am trying to display a binary image through an httphandler. Here is the

  • 0

I am trying to display a binary image through an httphandler. Here is the code I have:

ajax call

$.ajax({
    type: "GET",
    url: "AnswerPostHandler.ashx",
    data: "imgid=1380",
    success: function (msg) {
           $(parent).append(msg);
    },
    error: function (msg){
           alert(msg);
    }
});

Handler code

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "image/JPEG";
    try
    {
        krystaladbDataContext db = new krystaladbDataContext();

        var binimg = (from i in db.image_tables
                      where i.IMG_ID.Equals(1380)
                      select i.IMG_THUMB).Single();


        byte[] b = binimg.ToArray();
        MemoryStream ms = new MemoryStream(b);
        Image img = Image.FromStream(ms);
        img.Save(context.Response.OutputStream,
            System.Drawing.Imaging.ImageFormat.Jpeg);
    }
    catch (Exception ex)
    {
        context.Response.Write(ex);
    }
}

something still seems not right here and it is dumping binary data. Base64 encoding is also a choice here but I have tested it , and it doesn’t work on IE 7 ( literally chops part of the image ).

can you advice me on what i am doing wrong here and how I can make it right? thanks

  • 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-27T15:57:07+00:00Added an answer on May 27, 2026 at 3:57 pm

    Handler code,

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "image/JPEG";
        try
        {
            krystaladbDataContext db = new krystaladbDataContext();
            var binimg = (from i in db.image_tables
                          where i.IMG_ID.Equals(1380)
                          select i.IMG_THUMB).Single();
    
    
            byte[] b = binimg.ToArray();
            context.Response.BinaryWrite(b);
            context.Response.Flush();
        }
        catch (Exception ex)
        {
            context.Response.Write(ex);
        }
    }
    

    and html <img> markup,

    <img src="AnswerPostHandler.ashx?imgid=1380" alt="None" id="img1" />
    

    Or you may request via jQuery code:

     $("#showImageButton").click(function () {
                    $("#img1").attr("src", "AnswerPostHandler.ashx?imgid=1380");
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display an image using OpenGL ES through android NDK.. What
I have gone through every tutorial to display an image on an android phone
I have an array of Person pocos, populated below. I'm trying display them alphabetically
I am trying display values in a datagrid in my application. I have all
I' trying to display an image along with some text as a listbox item
I am trying to display an image which is fetched from the database as
I am trying to display random images heres my code private void Page_Load(object sender,
Trying to display a list filtered by the ‘term’ in autocomplete I have a
I am trying to return a binary from the DB using linq for display
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s

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.