1

私のプログラムでは、ユーザーは特定のサイズまで画像をアップロードでき、その後画像のサイズを変更しています。画像が大きい場合はうまく機能しますが、画像が小さい場合、大きな画像にサイズ変更しようとするとぼやけます(基本的には、サイズ変更ではなくズームするだけです)...どうすればそれを行うことができますか.Thank!!

これが私のプログラムです

 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