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.
Binary Image
Page 1 of 13 Replies - 1270 Views - Last Post: 08 February 2013 - 06:21 AM
Replies To: Binary Image
#2
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.
#3
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.
#4
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.
Please help me.
That is not the full code, i only showed the essential parts where i was receiving the fault.
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.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|