Generate a local hard-coded image and record the numbers on the image for comparison.

Source: Internet
Author: User

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


}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.