I have an ASP.NET web application that display some images. For thumbnail display, I have to resize them. Here is my code:
var newImage = new Bitmap(sourceImage, width, height);
var g = Graphics.FromImage(newImage);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(newImage, 0, 0, newImage.Width, newImage.Height);
newImage.Save(path,GetEncoder(ImageFormat.Jpeg), myEncoderParameters);
Everything looks ok if I run in LOCALHOST. However, when I publish on server, the image quality is very poor and broken.
As Microsoft documentation (http://msdn.microsoft.com/en-us/library/system.drawing.graphics.smoothingmode%28v=vs.110%29.aspx), the System.Drawing namespace is not support for some platform, but seems like that's not my case (I'm not very sure).
This is my server system specification: https://i.sstatic.net/ByVZ1.jpg (Please follow the link, I do not have enough reputation to post image).
Can anyone please help me with this. Thanks very much.
I got an answer by myself. The problem is when I call
g.DrawImage(newImage, 0, 0, newImage.Width, newImage.Height);
It will draw an resized image into itself, that is the object:
new Bitmap(sourceImage, width, height));
so all the settings of the graphic object is not affected. The resize functioned actually at the above line of code. The correct solution should be:
g.DrawImage(sourceImage, 0, 0, newImage.Width, newImage.Height);
And everything works now.