このコードが、サイズが556kbの241kbから600x375までの1280x800以前の画像のサムネイルを作成する理由がわかりません。コードは次のとおりです。C# - 同じ画像のより小さい解像度を作成した後に画像サイズが大きくなる
using (System.Drawing.Image img = System.Drawing.Image.FromFile(@"c:\images\myImg.jpg"))
{
int sourceWidth = img.Width;
int sourceHeight = img.Height;
int thumbHeight, thumbWidth = 0;
decimal ratio = decimal.Divide(sourceHeight, sourceWidth);
if (sourceHeight > 600 || sourceWidth > 800)
{
if (ratio >= 1) // Image is higher than it is wide.
{
thumbHeight = 800;
thumbWidth = Convert.ToInt32(decimal.Divide(sourceWidth, sourceHeight) * thumbHeight);
}
else // Image is wider than it is high.
{
thumbWidth = 600;
thumbHeight = Convert.ToInt32(decimal.Divide(sourceHeight, sourceWidth) * thumbWidth);
}
using (Bitmap bMap = new Bitmap(thumbWidth, thumbHeight))
{
Graphics gr = Graphics.FromImage(bMap);
gr.SmoothingMode = SmoothingMode.HighQuality;
gr.CompositingQuality = CompositingQuality.HighQuality;
gr.InterpolationMode = InterpolationMode.High;
Rectangle rectDestination = new Rectangle(0, 0, thumbWidth, thumbHeight);
gr.DrawImage(img, rectDestination, 0, 0, sourceWidth, sourceHeight, GraphicsUnit.Pixel);
bMap.Save(HttpContext.Current.Server.MapPath("~/i/" + filename + "_" + fileExtension));
}
}
}
ご協力いただければ幸いです。 よろしくお願いします。 Ben
*サイズ*を変更することは、画像の解像度*を変更することと同じではありません。 画像サイズを小さくすることで、より多くのピクセルがより少ないスペースにパックされます。 –
ほとんどの場合、入力画像の圧縮品質は低く、出力画像の圧縮品質は高くなります。 – Rotem