Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Image from dB, getting GDI+ generic error

Status
Not open for further replies.

jermine

Programmer
Jun 15, 2001
59
SG
I know there have been many posts on this topic, and I have looked at them but I am still having problems.

I have a jpeg image which was retrieved from the database and needed to display it in a user control.

In the code below, im trying to save the image into a blank image file and display it in the application.
When I try to save the image back to disk, then the good old highly descriptive "Generic error occurred in GDI+" exception is thrown.

A code snippet is provided below, any help would be appreciated.

thanks!

Jermine
Code:
byte[] imageBinary = GetImage();  
System.IO.MemoryStream mstream = new System.IO.MemoryStream (); 
mstream.Write (imageBinary, 0, imageBinary.Length);
Bitmap bitmap = new Bitmap (mstream); 
Response.ContentType = "image/pjpeg"; 
bitmap.Save(Server.MapPath("image.jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg); 
mstream.Close();
this.Image1.ImageUrl  = Server.MapPath("image.jpeg");
 
Maybe i'm missing something, but shouldnt it be

Response.ContentType="image/jpeg" ....not

Response.ContentType = "image/pjpeg";

??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top