'이미지'에 해당되는 글 2건

  1. 2011.04.12 이미지 영역 사격형 그리기 2
  2. 2010.09.09 이미지 Thumbnail(크기조정)

'c#' 카테고리의 다른 글

c# 람다식 모음  (1) 2012.08.07
combox text, value값 넣기  (1) 2011.01.05
Datagrid Column 갯수 가져오기  (0) 2010.11.18
dataGrid의 로우 카운트를 가져오는 방법  (0) 2010.11.18
클라이언트, 서버 프로그램[TcpClient 이용]  (1) 2010.11.01
Posted by 정광원
,



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

Posted by 정광원
,