Необходимо исходную большую картинку в формате *.jpeg уменьшить до нужного размера и сохранить в формате *.jpeg и *.gif.
Ресайз выполняет функция:
Код:
public static Image ResizeImage(Image img, int newWidth, int newHeight)
{
float ratio = (float)img.Width / (float)img.Height;
int target_height = (int)((float) newWidth / ratio);
if (target_height > newHeight && newHeight > 0)
{
target_height = newHeight;
newWidth = (int)((float)target_height * ratio);
} newHeight = target_height;
Image thumbImg = new Bitmap(newWidth, newHeight);
using (Graphics gr = Graphics.FromImage(thumbImg)) {
gr.DrawImage(img, new Rectangle(0, 0, newWidth, newHeight), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
}
return thumbImg;
}
Сохраняю следующим образом:
Image img = Image.FromFile(group_path);//...img.Save(group_path1, ImageFormat.Gif);
Качество ресайза и сохранения при данной реализации оставляет желать лучшего (такое же как в MS Paint). Посоветуйте, как можно добиться лучшего качества. Может есть какие-нибудь сторонние библиотеки?