0
我正在尝试调整图像大小的功能。调整大小后的图像有白色边框
public static Bitmap FixedSize(Bitmap imgPhoto, int Width, int Height, InterpolationMode im)
{
if ((Width == 0) && (Height == 0))
return imgPhoto;
if ((Width < 0) || (Height < 0))
return imgPhoto;
int destWidth = Width;
int destHeight = Height;
int srcWidth = imgPhoto.Size.Width;
int srcHeight = imgPhoto.Size.Height;
if (Width == 0)
destWidth = (int)(((float)Height/(float)srcHeight) * (float)srcWidth);
if (Height == 0)
destHeight = (int)(((float)Width/(float)srcWidth) * (float)srcHeight);
Bitmap bmPhoto = new Bitmap(destWidth, destHeight,
PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.Clear(Color.White);
grPhoto.InterpolationMode = im;
grPhoto.DrawImage(imgPhoto,
new Rectangle(new Point(0, 0), new Size(destWidth, destHeight)),
new Rectangle(0, 0, srcWidth, srcHeight),
GraphicsUnit.Pixel);
grPhoto.Dispose();
return new Bitmap(bmPhoto);
}
当我调试代码,所有的数字看起来不错,但是当我将图像保存它在左侧和顶部边框一条白线。任何想法什么应该是错的?我试图搜索,我使用完全相同的代码应该工作,但行仍然存在。
谢谢。
虽然我不明白为什么,它的工作原理!谢谢 :-) –