3 Replies - 3431 Views - Last Post: 08 February 2013 - 06:21 AM Rate Topic: -----

#1 merlin'sbeard  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 27-December 12

Binary Image

Posted 07 February 2013 - 09:50 AM

Okay, now i have an employee form with an image field at the top. Now i want to retrieve an image from a database, stored in bytes and display it an asp.net image control. I have tried so many solutions i found on the net but none worked. I want to do it without using any handlers or querystrings, all my data in my database passes through my class library to the web form. I am not using a gridview or any of the data controls.

I use Visual Studio 2010 and Sql server express 2005.

this is not a school project it is work related.

Is This A Good Question/Topic? 0
  • +

Replies To: Binary Image

#2 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 267
  • View blog
  • Posts: 1,470
  • Joined: 07-April 08

Re: Binary Image

Posted 07 February 2013 - 10:09 AM

So tell us; What have you tried? Also show us the code you are using, and the errors/issues you are running into. With out that there is really nothing much else we can do besides throw out a bunch of random solutions that you may or may not have already tried.
Was This Post Helpful? 0
  • +
  • -

#3 merlin'sbeard  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 27-December 12

Re: Binary Image

Posted 07 February 2013 - 10:38 AM

img = (byte[]dr.GetSqlValue(dr.GetOrdinal("EmpImage")));
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(img);
Response.Flush();
Response.End();



<asp:Image ID="imgEmployee" ImageUrl="EmployeeDetails.aspx" runat="server" Height="165px" Width="204px" />

This is contained within the page load event.

I also tried using a generic handler and converting the bytes within that handler and passing the handler as a Url to the image control but that didn't work either.
Was This Post Helpful? 0
  • +
  • -

#4 merlin'sbeard  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 20
  • Joined: 27-December 12

Re: Binary Image

Posted 08 February 2013 - 06:21 AM

Okay i tried this and i was able to convert the image from bytes and store it on a local folder. But the image never shows when i open the application in the browser.
protected void Page_Load(object sender, EventArgs e)
{
  EmpImage = (byte[])dr.GetValue(dr.GetOrdinal("EmpImage"));
  byteArrayToImage(EmpImage); 
}

private void byteArrayToImage(byte[] byteArrayIn)
{
  System.Drawing.Image newImage;
  string strFilename = @"C:\Pics\" + "Emp" + EmployeeID + ".jpg";

  if (byteArrayIn != null)
  {
    using (MemoryStream stream = new MemoryStream(byteArrayIn, 0, byteArrayIn.Length))
    {
      newImage = System.Drawing.Image.FromStream(stream);

      newImage.Save(strFileName);

      strFileName = @"file:///" + strFileName;

      ImgEmp.ImageUrl = strFileName;
      imgEmp.AlternateText = strFileName; 
    }

    System.Web.HttpContext.Current.Response.Write("<script LANGUAGE='Javascript'>alert('The image conversion was
    successful');</SCRIPT>");

    else
    {
        Response.Write("no image data found");
    }
  }
}



Please help me.

That is not the full code, i only showed the essential parts where i was receiving the fault.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1