【发布时间】:2013-12-17 05:56:54
【问题描述】:
我正在尝试制作调整图像大小的功能。
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);
}
当我调试代码时,所有数字似乎都正常,但是当我保存图像时,它的左侧和顶部边框上有一条白线。知道应该有什么问题吗?我尝试搜索并使用了完全相同的代码,该代码应该可以工作,但该行仍然存在。
谢谢。
【问题讨论】:
标签: c# image resize border line