I want store the image in SQL server table, and I successed but when I retrive that image on page, I found that the image has lost its transparency. The origional image is png/gif. I have resized that image in 100px / 100px.
I have used following code to resixe the image. It works but when it stores image in database it lost the transparency.
using (System.Drawing.Image oldImage = System.Drawing.Image.FromStream(new MemoryStrea开发者_JS百科m(imageFile)))
{
System.Drawing.Size newSize = CalculateDimensions(oldImage.Size, targetSize);
using (System.Drawing.Bitmap newImage = new System.Drawing.Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb))
{
using (System.Drawing.Graphics canvas = System.Drawing.Graphics.FromImage(newImage))
{
canvas.Clear(System.Drawing.Color.Transparent);
canvas.SmoothingMode = SmoothingMode.HighQuality;
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
canvas.DrawImage(oldImage, new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), newSize));
MemoryStream m = new MemoryStream();
newImage.Save(m, ImageFormat.Png);
return m.GetBuffer();
}
}
}
Any solution????
Thanks
This one probably answers your question:
Why does resizing a png image lose transparency?
As the above link suggests, you're not loosing transparency because the image is saved into the database. It's when you resize the image that the transparency is lost.
精彩评论