IMHO.WS

IMHO.WS (http://www.imho.ws/index.php)
-   Программирование (http://www.imho.ws/forumdisplay.php?f=40)
-   -   Ресайз картинок в .NET (http://www.imho.ws/showthread.php?t=116945)

andrei solovjev 21.03.2007 23:46

Ресайз картинок в .NET
 
Необходимо исходную большую картинку в формате *.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). Посоветуйте, как можно добиться лучшего качества. Может есть какие-нибудь сторонние библиотеки?

Gunslinger 22.03.2007 15:02

Ну можешь еще так изменить размеры:
Image l_ResultImage = null;
l_ResultImage = l_basePicture.GetThumbnailImage(l_newWidth, l_newHeiqht, null, IntPtr.Zero);

andrei solovjev 23.03.2007 09:43

Но все же, никто не знает как качественно сохранить в GIF???

andrei solovjev 24.03.2007 00:47

Нашел решение:
http://codebetter.com/blogs/brendan....6103.aspx#7056
Тема закрыта.


Часовой пояс GMT +4, время: 05:02.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.