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);
}
當我調試代碼,所有的數字看起來不錯,但是當我將圖像保存它在左側和頂部邊框一條白線。任何想法什麼應該是錯的?我試圖搜索,我使用完全相同的代碼應該工作,但行仍然存在。
謝謝。
雖然我不明白爲什麼,它的工作原理!謝謝 :-) –