1

在我的程序中,用户可以将图像上传到特定大小,然后我正在调整图像大小。如果图像很大,它会很好用,但是如果图像很小并且我尝试调整为大图像会变得模糊(基本上它只是缩放而不是调整大小)......有人可以帮助我怎么做。谢谢!

这是我的程序

 public static Image ScaleBySize(Image imgPhoto, int size)
        {
            int logoSize = size;

            float sourceWidth = imgPhoto.Width;
            float sourceHeight = imgPhoto.Height;
            float destHeight = 0;
            float destWidth = 0;
            int sourceX = 0;
            int sourceY = 0;
            int destX = 0;
            int destY = 0;




            if (sourceWidth > size || sourceWidth < size) { destWidth = size; }
            if (sourceHeight > size || sourceHeight < size) { destHeight = size; }


            Bitmap bmPhoto = new Bitmap((int)destWidth, (int)destHeight,PixelFormat.Format32bppPArgb);
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

            Graphics grPhoto = Graphics.FromImage(bmPhoto);
            grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
            grPhoto.DrawImage(imgPhoto,new Rectangle(destX, destY, (int)destWidth, (int)destHeight),new Rectangle(sourceX, sourceY, (int)sourceWidth, (int)sourceHeight),GraphicsUnit.Pixel);
            grPhoto.Dispose();

            return bmPhoto;
        }
4

1 回答 1

2

当然,您的大图像会模糊,因为小图像中没有细节。该程序只是“拉伸”每个像素以填充更大的区域。

于 2013-04-17T15:25:02.010 回答