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);
}
코드를 디버깅 할 때 모든 숫자는 괜찮은 것처럼 보이지만 이미지를 저장할 때 왼쪽과 위쪽 테두리에 흰색 선이 있습니다. 어떤 생각이 잘못 됐는지 알아? 검색을 시도했지만 정확히 동일한 코드를 사용했지만 작동해야하지만 줄은 아직 남아 있습니다.
감사합니다.
나는 왜 그런지 이해하지 못한다. 감사 :-) –