사용방법
file.SaveAs(TempPath + "\\" + oriFileName); //원본데이터 저장
param : 실제경록, 템프 경로, 이미지 이름, Thumbnail조정할 width, Thumbnail조정할 Height
GenerateThumbnail(TempPath + "\\" + oriFileName, TempPath, imgFileName, Width, Height);
#region ### 이미지 정렬 및 저장 ###
public static void GenerateThumbnail(string sImagePath, string sSavePath, string sSaveName, int iX, int iY)
{
using (System.Drawing.Image imgFull = System.Drawing.Image.FromFile(sImagePath))
{
System.Drawing.Imaging.ImageFormat ifFormat = imgFull.RawFormat;
int iNewX;
int iNewY;
if (imgFull.Width > iX || imgFull.Height > iY)
{
decimal dOrigWidth = imgFull.Width;
decimal dOrigHeight = imgFull.Height;
decimal dRatio;
if (iX / dOrigWidth < iY / dOrigHeight)
{
dRatio = iX / dOrigWidth;
}
else
{
dRatio = iY / dOrigHeight;
}
iNewX = Convert.ToInt32(dOrigWidth * dRatio);
iNewY = Convert.ToInt32(dOrigHeight * dRatio);
}
else
{
iNewX = imgFull.Width;
iNewY = imgFull.Height;
}
using (System.Drawing.Bitmap imgOutput = new System.Drawing.Bitmap(imgFull, iNewX, iNewY))
{
using (System.Drawing.Graphics gfxResizer = System.Drawing.Graphics.FromImage(imgOutput))
{
gfxResizer.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
gfxResizer.DrawImage(imgFull, 0, 0, iNewX, iNewY);
imgOutput.Save(sSavePath + "/" + sSaveName, ifFormat);
}
}
}
}
#endregion
'asp.net' 카테고리의 다른 글
Sys.WebForms.PageRequestManagerServerErrorException 500 (1) | 2010.09.10 |
---|---|
asp.net 이벤트 호출 순서 (2) | 2010.09.09 |
updatepanel 안에 Repeater사용 (2) | 2010.09.09 |
엑셀 다운로드 Server.Execute 사용해서 param값 던지기 (1) | 2010.09.09 |
javascript에서 dopostback 호출하기 (2) | 2010.09.09 |