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

Posted 寻梦园

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了生成本地难码图片并在本地记录图片上的数字以作比较相关的知识,希望对你有一定的参考价值。


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;
}


}

以上是关于生成本地难码图片并在本地记录图片上的数字以作比较的主要内容,如果未能解决你的问题,请参考以下文章

网站上的图片视频下载在本地

Dreamweaver如何批量替换网络图片地址

30Android 将本地图片转换为Base64加密字符串及根据加密串反向生成图片

一种本地边缘计算的仪表抓拍图片识别系统(成熟的AI识别算法])支持各种指针液晶数字仪表

H5调用本地相册/相机上传图片

php读取图片上的数字