/// <summary>
/// 퍼센트로 줄이기
/// </summary>
/// <param name="imgPhoto">사진 객체</param>
/// <param name="Percent">퍼센트</param>
/// <returns>수정된 Image</returns>
static Image ScaleByPercent(Image imgPhoto, int Percent)
{
//퍼센트 0.8 or 0.5 ..
float nPercent = ((float)Percent/100);
//넓이와 높이
int OriginalWidth = imgPhoto.Width;
int OriginalHeight = imgPhoto.Height;
//소스의 처음 위치
int OriginalX = 0;
int OriginalY = 0;
//움직일 위치
int adjustX = 0;
int adjustY = 0;
//조절될 퍼센트 계산
int adjustWidth = (int)(OriginalWidth * nPercent);
int adjustHeight = (int)(OriginalHeight * nPercent);
//비어있는 비트맵 객체 생성
Bitmap bmPhoto = new Bitmap(adjustWidth, adjustHeight, PixelFormat.Format24bppRgb);
//이미지를 그래픽 객체로 만든다.
Graphics grPhoto = Graphics.FromImage(bmPhoto);
//사각형을 그린다.
//그릴 이미지객체 크기, 그려질 이미지객체 크기
grPhoto.DrawImage(imgPhoto,
new Rectangle(adjustX,adjustY,adjustWidth,adjustHeight),
new Rectangle(OriginalX,OriginalY,OriginalWidth,OriginalHeight),
GraphicsUnit.Pixel);
grPhoto.Dispose();
return bmPhoto;
}
|