日期:2014-05-18  浏览次数:21174 次

图片缩小后再放大,然后就变得很模糊了,请问怎么办
如题,我缩小放大是直接改变图片长宽的。。。

------解决方案--------------------
C# code

HttpPostedFile upPhoto = photo.PostedFile;
                    int upPhotoLength = upPhoto.ContentLength;

                    System.Drawing.Image oldImage, newImage; //存放老图和新图

                    int imageLength = 60; //60k
                    int imageSize = 400;
                    if (upPhotoLength > imageLength * 1024)
                    {
                        //调整图片大小
                        oldImage = System.Drawing.Image.FromStream(upPhoto.InputStream);

                        newImage = Helper.ThumbnailImage(oldImage, imageSize);
                    }
                    else
                    {
                        newImage = System.Drawing.Image.FromStream(upPhoto.InputStream);
                    }

                    MemoryStream PhotoStream = new MemoryStream();
                    newImage.Save(PhotoStream, System.Drawing.Imaging.ImageFormat.Jpeg);

------解决方案--------------------
缩小图重新生成别覆盖原图吧
就像一般网站上图片新闻什么的,根据大图生成一张小的缩略图
------解决方案--------------------
C# code

public static System.Drawing.Image ThumbnailImage(System.Drawing.Image oldImage, int newSize)
    {
        decimal width = oldImage.Width;
        decimal height = oldImage.Height;
        int newwidth, newheight;
        if (width > height)
        {
            newwidth = newSize;
            newheight = (int)(height / width * newSize);
        }
        else
        {
            newheight = newSize;
            newwidth = (int)(width / height * newSize);
        }
        return oldImage.GetThumbnailImage(newwidth, newheight, null, IntPtr.Zero);

    }

------解决方案--------------------
这是肯定的。缩小图片信息量就减少了。否则还要图像压缩算法干什么。