Android栗子の图片验证码生成实例代码
废话不多说了,下面一段代码给大家分享android生成栗子图片验证码功能,具体代码如下所示;
importjava.util.Random; importandroid.graphics.Bitmap; importandroid.graphics.Bitmap.Config; importandroid.graphics.Canvas; importandroid.graphics.Color; importandroid.graphics.Paint; publicclassAutjcode{ privatestaticAutjcodebmpCode; privateintwidth=100,height=60; privateintbase_padding_left=15,range_padding_left=5, base_padding_top=25,range_padding_top=30; privateintcodeLength=4,line_number=2,font_size=25; privateStringcode; privateintpadding_left,padding_top; privatestaticfinalchar[]CHARS={'2','3','4','5','6','7','8', '9','a','b','c','d','e','f','g','h','j','k','l','m', 'n','p','q','r','s','t','u','v','w','x','y','z','A', 'B','C','D','E','F','G','H','I','J','K','L','M','N', 'P','Q','R','S','T','U','V','W','X','Y','Z'}; /** *获得实例 * *@return */ publicstaticAutjcodegetInstance(){ if(bmpCode==null) bmpCode=newAutjcode(); returnbmpCode; } privateRandomrandom=newRandom(); /** *创建位图 * *@return */ publicBitmapcreateBitmap(){ padding_left=0; //ARGB_8888表示为32位的ARGB位图 Bitmapbp=Bitmap.createBitmap(width,height,Config.ARGB_8888); Canvasc=newCanvas(bp); code=createCode(); c.drawColor(Color.WHITE); Paintpaint=newPaint(); paint.setTextSize(font_size); paint.setFakeBoldText(true); for(inti=0;i使用方法:
初始化:
registerAuthimg=(ImageView)findViewById(R.id.registerAuthimg); registerAuthimg.setImageBitmap(Autjcode.getInstance().createBitmap());验证码刷新:
registerAuthimg.setImageBitmap(Autjcode.getInstance().createBitmap());获取当前显示的文字验证码:
StringAutecodeimg=Autjcode.getInstance().getCode().toUpperCase();总结
以上所述是小编给大家介绍的Android栗子の图片验证码生成实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!