Android自定义View之验证码

时间:2020-09-21 04:46:21
【文件属性】:

文件名称:Android自定义View之验证码

文件大小:19.85MB

文件格式:RAR

更新时间:2020-09-21 04:46:21

Android 验证码

for (int i = 1; i <= mTextCount; i++) { int offsetDegree = mRandom.nextInt(15); // 这里只会产生0和1,如果是1那么正旋转正角度,否则旋转负角度 offsetDegree = mRandom.nextInt(2) == 1 ? offsetDegree : -offsetDegree; canvas.save(); canvas.rotate(offsetDegree, mWidth / 2, mHeight / 2); // 给画笔设置随机颜色 mTextPaint.setARGB(255, mRandom.nextInt(200) + 20, mRandom.nextInt(200) + 20, mRandom.nextInt(200) + 20); canvas.drawText(String.valueOf(mText.charAt(i - 1)), (i - 1) * charLength * 1.6f + 30, mHeight * 2 / 3f, mTextPaint); canvas.restore(); } // 产生干扰效果1 -- 干扰点 for (PointF pointF : mPoints) { mPointPaint.setARGB(255, mRandom.nextInt(200) + 20, mRandom.nextInt(200) + 20, mRandom.nextInt(200) + 20); canvas.drawPoint(pointF.x, pointF.y, mPointPaint); } // 产生干扰效果2 -- 干扰线 for (Path path : mPaths) { mPathPaint.setARGB(255, mRandom.nextInt(200) + 20, mRandom.nextInt(200) + 20, mRandom.nextInt(200) + 20); canvas.drawPath(path, mPathPaint); }


网友评论