• 生成本地难码图片并在本地记录图片上的数字以作比较



    1.用法

    Bitmap valimg = new CreateValiImage(this).onDraw();




    public class CreateValiImage {
    private Paint paint;
    private Canvas canvas;
    private float width;
    private float height;
    private int retate = 6;
    private SharedUtils sharedUtils;

    private Context context;


    public CreateValiImage(Context context) {
    this.context = context;
    sharedUtils = new SharedUtils(context);
    paint = new Paint();
    width = context.getResources().getDimension(R.dimen.register_img_100);
    height = context.getResources().getDimension(R.dimen.frame_title);


    }


    public Bitmap onDraw() {
    Bitmap bitmap = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_8888);
    canvas = new Canvas(bitmap);
    //画背景
    paint.setColor(Color.GRAY);
    RectF rectF = new RectF(0, 0, width, height);
    canvas.drawRect(rectF, paint);
    //画干扰线
    paint.setStrokeWidth(2);
    for (int i = 0; i < 7; i++) {
    paint.setColor(Color.rgb(getValiNum(0, 255), getValiNum(0, 255), getValiNum(0, 255)));
    canvas.drawLine(getValiNum(0, (int) width), getValiNum(0, (int) height), getValiNum(0, (int) width), getValiNum(0, (int) height), paint);
    }

    //画文字
    paint.setTextSize(60);
    paint.setStrokeWidth(1);
    StringBuffer stringBuffer = new StringBuffer();
    for (int i = 0; i < 4; i++) {
    paint.setColor(Color.rgb(getValiNum(0, 255), getValiNum(0, 255), getValiNum(0, 255)));
    canvas.rotate(getValiNum(0, retate), 0f, 0f);
    int item = getValiNum(0, 9);
    stringBuffer.append(item);
    canvas.drawText(item + "", 20 + (60 * i), 70, paint);
    canvas.rotate(-1 * getValiNum(0, retate), 0f, 0f);
    }
    sharedUtils.setValiNum(stringBuffer.toString());

    return bitmap;
    }

    public int getValiNum(int begin, int end) {
    Random random = new Random();
    return random.nextInt(end - begin) + begin;
    }


    }
  • 相关阅读:
    【流量劫持】SSLStrip 终极版 —— location 瞒天过海
    【流量劫持】沉默中的狂怒 —— Cookie 大喷发
    【流量劫持】SSLStrip 的未来 —— HTTPS 前端劫持
    Web 前端攻防(2014版)
    流量劫持 —— 浮层登录框的隐患
    流量劫持能有多大危害?
    流量劫持是如何产生的?
    XSS 前端防火墙 —— 整装待发
    XSS 前端防火墙 —— 天衣无缝的防护
    XSS 前端防火墙 —— 无懈可击的钩子
  • 原文地址:https://www.cnblogs.com/zhou2016/p/5316394.html
Copyright © 2020-2023  润新知