【发布时间】:2014-02-02 14:55:48
【问题描述】:
我正在保存原始图片及其缩略图,但缩略图大小比原始图片大。
if (fu_photo.HasFile)
{
fu_photo.SaveAs(Server.MapPath("../media/" + fu_photo.FileName));
Bitmap orgimg = new Bitmap(fu_photo.FileContent);
double orgWidth = orgimg.Width;
double orgHeight = orgimg.Height;
double orgRatio = orgWidth / orgHeight;
int newWidth = 256;
int newHeight = Convert.ToInt32(Convert.ToDouble(newWidth) / orgRatio);
Bitmap newimg = new Bitmap(orgimg, newWidth, newHeight);
Graphics gimg = Graphics.FromImage(newimg);
gimg.InterpolationMode = InterpolationMode.HighQualityBicubic;
gimg.SmoothingMode = SmoothingMode.AntiAlias;
gimg.CompositingQuality = CompositingQuality.HighQuality;
gimg.PixelOffsetMode = PixelOffsetMode.HighQuality;
// gimg.FillRectangle(Brushes.White, 0, 0, newWidth, newHeight);
gimg.DrawImage(newimg, 0, 0, newWidth, newHeight);
newimg.Save(Server.MapPath("../media/256_" + fu_photo.FileName));
orgimg.Dispose();
newimg.Dispose();
gimg.Dispose();
}
这是我的代码。我用一张 680x382px 93kB 的照片试了一下。它将原始的保存为 93kB,但将缩略图保存为 256x144px 和 97kB! 当我尝试使用 Photoshop 以高质量和 256x144 像素保存时,它保存为 18kB。 如何减小图像文件的大小?
【问题讨论】:
标签: asp.net file-upload jpeg image-compression