Reputation: 386
I am working on a project which requires to stored the 32x32 size Icons(png) in table. I am storing the image in table, but when I am getting it to display on page it feels something distorted. These are the png images so somewhere it could be transparent. But when I am showing that image in list of asp.Net page the transparent spaces are filled with black color.
Are there any ways/methods to store the png image in the table without distorting it's quality.
Thanks
Upvotes: 3
Views: 216
Reputation: 6805
This happens when you save Image to byte array with wrong ImageFormat. Use this code:
public byte[] imageToByteArray(string imagePath)
{
return imageToByteArray(System.Drawing.Image.FromFile(imagePath));
}
public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
byte[] result = null;
using (MemoryStream ms = new MemoryStream())
{
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
result = ms.ToArray();
}
return result;
}
Upvotes: 3