Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> 生成本地難碼圖片並在本地記錄圖片上的數字以作比較,圖片記錄

生成本地難碼圖片並在本地記錄圖片上的數字以作比較,圖片記錄

編輯:關於android開發

生成本地難碼圖片並在本地記錄圖片上的數字以作比較,圖片記錄



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


}

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved