画像の種類 (bmp、jpg、png など) に関係なく、比例して画像のサイズを変更することはできますか?
私はこのコードを持っていて、何かが欠けていることを知っています (しかし何がわからない):
public bool ResizeImage(string fileName, string imgFileName,
ImageFormat format, int width, int height)
{
try
{
using (Image img = Image.FromFile(fileName))
{
Image thumbNail = new Bitmap(width, height, img.PixelFormat);
Graphics g = Graphics.FromImage(thumbNail);
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
Rectangle rect = new Rectangle(0, 0, width, height);
g.DrawImage(img, rect);
thumbNail.Save(imgFileName, format);
}
return true;
}
catch (Exception)
{
return false;
}
}
可能でない場合、jpeg 画像をプロポーショナルにサイズ変更するにはどうすればよいですか?
このメソッドを使用することは知っていますが、これをどこに置くべきかわかりません (!)。