国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

圖片驗證碼

2024-07-21 02:25:47
字體:
來源:轉載
供稿:網友

#region"自定義"http://驗證碼
  private void createcheckcodeimage()
  {
   session["checkcode"]=null;
   string checkcode=this.createcheckcode(4).trim();
   if(checkcode==null || checkcode==string.empty)
   {
    return;
   }
   else
    session["checkcode"]=checkcode;
   system.drawing.bitmap image = new system.drawing.bitmap((int)math.ceiling(((double)checkcode.length * 13)), 24);
   graphics g = graphics.fromimage(image);//http://localhost/dx/global.asax
   try
   {
    //生成隨機生成器
    random random = new random();
    //清空圖片背景色
    g.clear(color.white);
    //畫圖片的背景噪音線
    for(int i=0; i<25; i++)
    {
     int x1 = random.next(image.width);
     int x2 = random.next(image.width);
     int y1 = random.next(image.height);
     int y2 = random.next(image.height);
     g.drawline(new pen(color.silver), x1, y1, x2, y2);
    }
    font font = new system.drawing.font("arial", 13, (system.drawing.fontstyle.bold | system.drawing.fontstyle.italic));
    system.drawing.drawing2d.lineargradientbrush brush = new system.drawing.drawing2d.lineargradientbrush(new rectangle(0, 0, image.width, image.height), color.blue, color.darkred, 1.2f, true);
    g.drawstring(checkcode, font, brush, 2, 2);
    //畫圖片的前景噪音點
    //    for(int i=0; i<100; i++)
    //    {
    //     int x = random.next(image.width);
    //     int y = random.next(image.height);
    //     image.setpixel(x, y, color.fromargb(random.next()));
    //    }
    //畫圖片的邊框線
    g.drawrectangle(new pen(color.silver), 0, 0, image.width - 1, image.height - 1);

    system.io.memorystream ms = new system.io.memorystream();
    image.save(ms, system.drawing.imaging.imageformat.gif);
    response.clearcontent();
    response.contenttype = "image/gif";
    response.binarywrite(ms.toarray());
   }
   finally
   {
    g.dispose();
    image.dispose();
   }
  }
  private string createcheckcode(int length)
  {
   int number;
   char code=(char)0;
   string checkcode = string.empty;

   system.random random = new random();

   for(int i=0; i<length;i++)
   {
    number = random.next();

    //if(number % 2 == 0)
    code = (char)('0' + (char)(number % 10));
    //    else
    //     code = (char)('a' + (char)(number % 26));
    checkcode += code.tostring();
   }
   return checkcode;
  }
  #endregion


 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江孜县| 左贡县| 万源市| 郎溪县| 渭南市| 娄底市| 调兵山市| 乳源| 繁昌县| 阿拉善盟| 慈利县| 六枝特区| 铅山县| 长葛市| 商丘市| 泗洪县| 长宁区| 如东县| 容城县| 和顺县| 杂多县| 汝城县| 金昌市| 萍乡市| 合川市| 聂拉木县| 多伦县| 台中市| 山西省| 保定市| 兴隆县| 曲麻莱县| 勃利县| 霍山县| 新巴尔虎左旗| 辽中县| 林州市| 甘孜| 新和县| 瑞金市| 黄山市|