缩放图像时的差异

时间:2015-10-09 18:28:50

标签: c# graphics drawimage

我需要缩放图像,我使用图形来解决这个问题。我使用DrawImage,传递原始图像,新位置(0,0)和新尺寸。缩放结果图像,但其上边缘和左边缘是透明的。谁知道为什么? 我的代码:

Rectangle DstRec = new Rectangle(0, 0, (int) (CurrentImage.ImgBM.Width * Zoom), (int) (CurrentImage.ImgBM.Height * Zoom));
//ReducedBM = new Bitmap((int)(CurrentImage.ImgBM.Width * Zoom), (int)(CurrentImage.ImgBM.Height * Zoom));
ReducedBM = new Bitmap(CurrentImage.ImgBM, DstRec.Width, DstRec.Height);
Graphics g = Graphics.FromImage(ReducedBM);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//g.DrawImage(CurrentImage.ImgBM, 0, 0, (int)(CurrentImage.ImgBM.Width * Zoom), (int)(CurrentImage.ImgBM.Height * Zoom));
g.DrawImage(CurrentImage.ImgBM, DstRec);
g.Dispose();

1 个答案:

答案 0 :(得分:0)

我认为这一行存在问题:

g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

将其更改为此。

g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;