Generate a local hard-coded image and record the numbers on the image for comparison.
1. Usage
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 );
// Draw the background
Paint. setColor (Color. GRAY );
RectF rectF = new RectF (0, 0, width, height );
Canvas. drawRect (rectF, paint );
// Draw interference lines
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 );
}
// Draw text
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;
}
}