Android繪製驗證碼

2021-08-03 08:41:35 字數 1431 閱讀 1060

在前面仿華為載入動畫、仿網易**聽歌識曲-麥克風動畫中,我們通過繪圖的基礎知識完成了簡單的繪製。在本例中,我們將繪製常見的驗證碼。

通過上面的效果圖觀察,我們可以看到裡面有繪製的隨機線條,隨機繪製的驗證碼。

/**

* created by iflytek_dsw on 2017/7/3.

*/public

class

identifycodeutil ;

private

static

identifycodeutil instance;

public

static

identifycodeutil

getinstance()

return instance;

}public

bitmap

createbitmapcode(int

width, int

height)

/*** 返回驗證碼

* @return 驗證碼生成的字串

*/ public

string

getidentifycode()

return stringbuffer.tostring();

}/**

* 生成驗證碼

* @return

*/ private

string

buildidentifycode()

log.d("code"

,stringbuffer.tostring());

return stringbuffer.tostring();

}/**

* 繪製文字

* @param canvas 畫布

* @param width 寬度

* @param height 高度

*/ private

void

drawcodetext(canvas

canvas,int

width, int

height)

}/**

* 生成干擾線

* @param canvas

* @param width

* @param height

*/ private

void

drawlines(canvas

canvas,int

width, int

height)

}/**

* 生成干擾點

*/ private

void

drawpoint(canvas

canvas, int

width, int

height) }}

繪製驗證碼

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 填充背景色...

canvas繪製驗證碼

好的 都是一行一行敲出來的,為了明天加油!一 在html中建立乙個canvas並設定乙個 id 和寬高 id c3 width 120 height 30 二 利用css給canvas設定乙個背靜屬性,在網頁中顯示出來。body canvas 三 最重要的,利用js建立矩形 1.首先通過js原生do...