日期:2014-05-20  浏览次数:20391 次

关于图片压缩
我使用SharpZipLib压缩和解压图片,压缩后的压缩包是没有问题的,但是解压后图片有损失,有没有人有这方面的经验的人告诉一下是什么原因造成的。

------解决方案--------------------
我的一个图片缩小放大方法,希望对你有帮助
public void reDrawSaveImage(System.IO.Stream imgStream,string savePath,int upWidth,int upHeight)
{
int oldWidth;
int oldHeight;
int newWidth;
int newHeight;

newWidth = upWidth;
newHeight = upHeight;

System.Drawing.Image oldImg = System.Drawing.Image.FromStream(imgStream);

oldWidth = oldImg.Width;
oldHeight = oldImg.Height;

if(oldWidth > = oldHeight)
{
newHeight = (int)Math.Floor(Convert.ToDouble(oldHeight) * Convert.ToDouble(newWidth) / Convert.ToDouble(oldWidth));
}
else
{
newWidth = (int)Math.Floor(Convert.ToDouble(oldWidth) * Convert.ToDouble(newHeight) / Convert.ToDouble(oldHeight));
}

Bitmap newImg = new Bitmap(newWidth,newHeight);
Graphics g = Graphics.FromImage(newImg);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量插值法
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;//设置高质量,低速度呈现平滑程度
g.Clear(Color.Transparent); //清空画布并以透明背景色填充
g.DrawImage(oldImg,new Rectangle(0,0,newWidth,newHeight),new Rectangle(0,0,oldWidth,oldHeight),GraphicsUnit.Pixel);
newImg.Save(savePath,System.Drawing.Imaging.ImageFormat.Jpeg);

g.Dispose();
oldImg.Dispose();
newImg.Dispose();

}