자동가입방지번호 구현

using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;

using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;



namespace Home.Inc.RamdomImages.DoubleOnline
{
    public partial class ComfirmBitmapHandler1 : Web.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "image/jpeg";                            // 보내는 형식을 "image/jpeg"형태라고 지정해준다
            // 이미지 사이즈
            int lenX = 85, lenY = 20;
            Bitmap bm = new Bitmap(lenX, lenY);
            Graphics g = Graphics.FromImage(bm);
            // 배경으로 그라데이션 처리
            LinearGradientBrush bgGr = new LinearGradientBrush(
            new Point(0, 0),
            new Point(lenX, lenY),
            Color.Blue,
            Color.Black);
            g.FillRectangle(bgGr, 0, 0, lenX, lenY);  //배경적용

            // 5자리 숫자의 난수를 발생하여 텍스트를 만든다          
            string text = string.Empty;
            Random rnd = new Random();
            for (int i = 0; i < 5; i++)
            {
                text += rnd.Next(9).ToString();
            }
            // 텍스트를 그린다.
            Brush textBrush = new SolidBrush(Color.White);
            g.DrawString(text, new Font("굴림", 14), textBrush, 9, 0, StringFormat.GenericDefault);
            // 스트림에 비트맵을 쓴다.
            bm.Save(Response.OutputStream, ImageFormat.Jpeg);

            // 세션 생성후 5자리 숫자를 세션에 담는다.
            //SystemX.Web.SessionState.HttpSessionState session = (SystemX.Web.SessionState.HttpSessionState)HttpContext.Current.Items["ASP.NET_SESSIONSTATE"];   // 추가된 세션을 사용선언
            Session["ValidateString"] = text;
        }
    }
}


//-> 사용 <img runat="server" id="imgRm" alt="" src='../../Inc/RamdomImages/DoubleOnline/ComfirmBitmapHandler.aspx' />
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Previous
Next Post »