Hjælp til at resize
Jeg bruger følgende til at resize mine jpg billeder:public static Bitmap resizeImage(string filePath, int width, int height)
{
System.Drawing.Bitmap bmpOut = null;
try
{
Bitmap bmp = new Bitmap(filePath);
if(height == 0)
{
double tmpHeight = ((double)bmp.Height/(double)bmp.Width) * width;
height = (int)tmpHeight;
}
if(width == 0)
{
double tmpWidth = ((double)bmp.Width/(double)bmp.Height) * height;
width = (int)tmpWidth;
}
bmpOut = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bmpOut);
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
// g.FillRectangle(Brushes.White, 0, 0, width, height);
g.DrawImage(bmp, 0, 0, width, height);
bmp.Dispose();
GC.Collect();
}
catch
{
return null;
}
return bmpOut;
}
Men den laver ikke nogle særlige flotte billeder. Hvad kan jeg gøre for at optimere den funktion?
