深入c 繪製驗證碼的詳解

2022-09-26 09:21:09 字數 1098 閱讀 5458

1.使用乙個picturebox空間,使用乙個按鈕,以重新整理驗證碼。

2.首先定義checkcode()方法,以生成4為英文及數字組成的字串序列:

複製** **如下:

private string checkcode()

return checkcode;

}3.自定義codeimage()方法,將checkcode()方法生成的序列轉化為並顯示:

複製** **如下:

private void codeimage(string checkcode)

system.drawing.bitmap image=new system.drawing.bitmap((int)math.ceiling((checkcode.length*50.0)),50);

graphics g=graphics.fromimage(image);

tryfont font = new system.drawing.font("arial", 30, (system.drawing.fontstyle.bold));

g.drawstring(checkcode, font, new solidbrush(color.red), 2, 2);

for (int i = 0; i < 200; i++)

www.cppcns.com;          

g.drawrectangle(new pen(color.silver), 0, 0, image.width - 1, image.height - 1);

this.picturebox1.width = image.width;

this.picturebox1.height = image.height;

this.picturebox1.backgroundimage = image;

}catch

}4.複製** **如下:

private void form1_load(object sender, eventargs e)

private void button1_click(object sender, eventargs e)

本文標題: 深入c#繪製驗證碼的詳解

本文位址:

繪製驗證碼

public partial class validatecode validatebase 生成驗證碼 private string createvalidatecode base.strvalidate validatecode 儲存驗證碼 return validatecode 影象背景 pr...

驗證碼繪製

驗證碼繪製 1.產生驗證碼字串 使用ascii碼和sprintf函式生成驗證碼字串 ascii碼對應字元如下 數字 48 57 小寫字母 97 122 大寫字母 65 90 sprintf c ascii 將ascii碼轉為對應字元2.繪製驗證碼 繪製步驟 1 建立畫布 2 建立畫筆 3 填充背景色...

Android繪製驗證碼

在前面仿華為載入動畫 仿網易 聽歌識曲 麥克風動畫中,我們通過繪圖的基礎知識完成了簡單的繪製。在本例中,我們將繪製常見的驗證碼。通過上面的效果圖觀察,我們可以看到裡面有繪製的隨機線條,隨機繪製的驗證碼。created by iflytek dsw on 2017 7 3.public class i...