Click here to Skip to main content
16,013,648 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I inserted a transparent image (.png) in my database but when retrieving the image, the background became black,. Why?
Posted
Comments
Sergey Alexandrovich Kryukov 16-Jun-11 23:39pm    
It cannot be so. Details, please. Did you really compare binary files? How do you know what happened, exactly?
--SA
tedhanna 17-Jun-11 0:00am    
here is my code
saving the image:
Bitmap pictype = new Bitmap(pbSignature.Image);
MemoryStream _Stream = new MemoryStream();
pictype.Save(_Stream, ImageFormat.Jpeg);
blUser.Signature = _Stream.GetBuffer();


retrieving the image:
MemoryStream _Stream = new MemoryStream(blUserDetails.Signature);
pbSignature.Image = Image.FromStream(_Stream);


The data type of my column in database is Image.
when uploading the image to the picturebox it is just fine but when retrieving the image background become black.
tedhanna 17-Jun-11 0:05am    
I resolved it by myself i just changed the pictype.Save(_Stream, ImageFormat.Jpeg); to pictype.Save(_Stream, ImageFormat.Png);

since the Jpeg format won't allow transparent image that's why the background becomes black.

1 solution

I resolved it by myself i just changed the

pictype.Save(_Stream, ImageFormat.Jpeg);
to
pictype.Save(_Stream, ImageFormat.Png);

since the Jpeg format won't allow transparent background of an image that's why the background becomes black.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900