using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace GdiPlus { /// /// ThumbNail : 축소판 이미지 만들기 /// public class ThumbNail : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { //변수 초기화 int boxWidth = 100; int boxHeight = 100; double scale = 0; //파일 이름을 설정 string strFileName = String.Empty; string strSelectedFile = String.Empty; if(Request["FileName"] != null) { strSelectedFile = Request.QueryString["FileName"]; } else { strSelectedFile = "./sample.jpg"; } strFileName = Server.MapPath(strSelectedFile); int tmpW = Convert.ToInt32(Request.QueryString["Width"]); int tmpH = Convert.ToInt32(Request.QueryString["Height"]); if(tmpW > 0 && tmpH > 0) { boxWidth = tmpW; boxHeight = tmpH; } //새 이미지 생성 Bitmap b = new Bitmap(strFileName); //크기 비율을 계산한다. if(b.Height < b.Width) { scale = ((double)boxHeight)/b.Width; } else { scale = ((double)boxWidth)/b.Height; } //새 너비와 높이를 설정한다. int newWidth = (int)(scale*b.Width); int newHeight = (int)(scale*b.Height); //출력 비트맵을 생성, 출력한다. Bitmap bOut = new Bitmap(b, newWidth, newHeight); bOut.Save(Response.OutputStream, b.RawFormat); //마무리 b.Dispose(); bOut.Dispose(); } #region Web Form 디자이너에서 생성한 코드 override protected void OnInit(EventArgs e) { // // CODEGEN: 이 호출은 ASP.NET Web Form 디자이너에 필요합니다. // InitializeComponent(); base.OnInit(e); } /// /// 디자이너 지원에 필요한 메서드입니다. /// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }