ASP.NET 기초 강의실

시삽: 레드플러스 님 
게시판 이동:
 제목 : ThumbNail.ascx.cs
글번호: 287
작성자: 레드플러스
작성일: 2008/07/10 오후 2:43:00
조회수: 4422
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();            
    }
}
 
이전 글   다음 글 삭제 수정 답변 글쓰기 리스트


관련 아티클 리스트
  제       목 파일 작성자 작성일 조회
이전글 [!] 답변형 게시판 : /WebReply/ - 레드플러스 2008-07-14 5468
  [!] 사진 게시판 : /WebPhoto/ - 레드플러스 2008-07-10 7295
  테이블 및 저장 프로시저 - 레드플러스 2008-07-10 5266
  PhotoAdd.ascx - 레드플러스 2008-07-10 4708
  PhotoAdd.ascx.cs - 레드플러스 2008-07-10 4582
  ThumbNail.ascx - 레드플러스 2008-07-10 4285
현재글 ThumbNail.ascx.cs - 레드플러스 2008-07-10 4422
다음글 [!] 자료실 게시판 만들기 : Enterprise Library V4.0 사용 - 레드플러스 2008-07-09 7392
 
손님 사용자 Anonymous (손님)
로그인 Home