0

我有这段代码可以将图像大小调整为 300x300。但是在调整大小后,图像仍然失去了它的质量。我已经尝试过在其他网站上发布的其他解决方案,这些解决方案与此代码具有相同的代码实现,但它对我不起作用。请帮我解决一下这个。

Stream ream = FileUploadPic.FileContent;
            System.Drawing.Image i = new Bitmap(ream);

            Bitmap Orig_Photo = new Bitmap(i);
            Bitmap resize_Photo = new Bitmap(300,300);
            Graphics thumbnailGraph = Graphics.FromImage(resize_Photo);
            thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
            thumbnailGraph.SmoothingMode = SmoothingMode.AntiAlias;
            thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
            thumbnailGraph.PixelOffsetMode = PixelOffsetMode.HighQuality;

            var imageRectangle = new Rectangle(0, 0, 300, 300);
            thumbnailGraph.DrawImage(i, imageRectangle);
            System.Drawing.Image ii = new Bitmap(resize_Photo);
4

1 回答 1

0

我用过这个代码一次,所以你可以试试这个,这是c#版本

  Bitmap img = new Bitmap(newW, newH);
        using (Graphics g = Graphics.FromImage(img))
        {
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.DrawImage(srcImage, new Rectangle(0, 0, newW, newH));
        }

这里是您要重新调整图像大小的新高度和宽度newWnewH

您还需要包括using System.Drawing;名称空间。

于 2013-04-12T05:40:54.867 回答