사용방법
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