Ciao a tutti, ho un problema dovrei ridimensionare un immagine senza perdere qualità.
Navigando per la rete ho trovato vari esempi ecco quello che ho scelto:
private void ResizeAndSave(String imgSrc, int width, int height, string dirName)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(imgSrc);
Bitmap bmp = new Bitmap(width, height);
bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);
Graphics g = Graphics.FromImage(bmp);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
Rectangle rectangle = new Rectangle(0, 0, width, height);
// g.DrawImage(img, rectangle, -2, -2, img.Width - 2, img.Height - 2, GraphicsUnit.Pixel);
g.DrawImage(img, rectangle);
bmp.Save(dirName + fileName);
img.Dispose();
bmp.Dispose();
}
Tutto funziona salvo l'immagine ridimensionata, però mi siforma un fastidioso bordino a destra e in basso all'immagine.
Sempre cercando ho scoperto che dovrebbe essere un problema delle GDI ma non saprei come risolverlo.
Grazie in anticipo per la risposta!