제목 : ThumbNail.ascx.cs
    
    
        
            
                | 글번호: |  | 287 | 
            
                | 작성자: |  | 레드플러스 | 
            
                | 작성일: |  | 2008/07/10 오후 2:43:00 | 
            
            
                | 조회수: |  | 5703 | 
            
        
     
 
    
	
	
    
	using System;
using System.Drawing;
public partial class Photo_ThumbNailControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, 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 = "./mybook.jpg";//기본 이미지로 초기화
        }
        strFileName =
            Server.MapPath("./files/" + 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();            
    }
}