【问题标题】:Asp.Net Jpeg CompressionAsp.Net Jpeg 压缩
【发布时间】: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


    【解决方案1】:

    因为您将低质量图像映射到高质量图像, 这个怎么样?

    FileUpload1.PostedFile.SaveAs(ServerPatch + fileName);        
    System.Drawing.Image thumb = image.GetThumbnailImage(_Width,_Height, () => false, IntPtr.Zero);
    thumb.Save(ServerPatch + "/thumb/" + fileName);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-29
      • 2011-08-09
      • 1970-01-01
      • 2013-02-22
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      相关资源
      最近更新 更多