1
我正在爲攝影師創建一個投資組合網站。如何處理大圖像大小?
我面臨將照片大小調整爲小的問題。如果我縮小了尺寸,許多質量都會丟失。我如何壓縮圖片以免失去質量?
我的代碼:
using (var input = new Bitmap(imageFile.InputStream))
{
int width;
int height;
if (input.Width > input.Height)
{
width = 411 * input.Width/input.Height;
height = 411;
}
else
{
height = 411;
width = 411 * input.Width/input.Height;
}
using (var thumb = new Bitmap(width, height))
using (var graphic = Graphics.FromImage(thumb))
{
graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphic.SmoothingMode = SmoothingMode.AntiAlias;
graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphic.DrawImage(input, 0, 0, width, height);
using (var output = System.IO.File.Create(imagePath))
{
thumb.Save(output, ImageFormat.Jpeg);
}
}
}
你想放大圖片嗎? – Botonomous
[高質量圖像縮放C#]的可能重複(http://stackoverflow.com/questions/249587/high-quality-image-scaling-c-sharp) –