Lineargradient linear Rendering

Source: Internet
Author: User
Tags drawtext
Import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. lineargradient; import android. graphics. paint; import android. graphics. shader; import android. view. view;/*** @ version 10:45:28 **/public class mygameview extends view implements runnable {int bitwidth = 0; int bitheight = 0; paint mpaint = NULL; // linear gradient rendering shader mlineargrad Ient1 = NULL; // linear gradient rendering shader mlineargradient2 = NULL; // linear gradient rendering shader mlineargradient3 = NULL; Public mygameview (context) {super (context ); // create a lineargradient and set the gradient color array // The first vertex. The second vertex number indicates that the gradient start vertex can be set to any position on the diagonal corner and the third vertex, the fourth vertex number indicates the gradient end point // The Fifth vertex number indicates the gradient color // The sixth vertex number can be blank, indicating the coordinates, the value is 0-1 new float [] {0.25f, 0.5f, 0.75f, 1} // If This Is null, the color is evenly distributed along the ladder. // The Seventh color indicates the tile method. // clamp repeats the last color until the last color. // the image that is repeatedly colored by mirror is filled in either the horizontal or vertical direction with an image with a flip effect. // repeat repeatedly colored image horizontal or vertical direction mlineargradient1 = new lineargradient (0, 0, 0,100, new int [] {color. red, color. green, color. blue, color. white}, null, shader. tilemode. clamp); mlineargradient2 = new lineargradient (0, 0, 0,100, new int [] {color. red, color. green, color. blue, color. white}, null, shader. tilemode. mirror); mlineargradient 3 = new lineargradient (0, 0, 0,100, new int [] {color. red, color. green, color. blue, color. white}, null, shader. tilemode. repeat); mpaint = new paint (); New thread (this ). start () ;}@ override protected void ondraw (canvas) {// The height of lineargradient is only 100, and the rectangle drawn is 200. So it will be repeated. // assuming that the height of the two is the same as that of clamp, it is impossible to see the effect of painting = new paint (); paint. settextsize (20); paint. setcolor (color. white); // draw the gradient rectangle mpaint. set Shader (mlineargradient1); canvas. drawrect (0, 0,200,200, mpaint); canvas. drawtext ("Clamp", 0,200 + 20, paint); // draw the gradient rectangle mpaint. setshader (mlineargradient2); canvas. drawrect (0,250,200,450, mpaint); canvas. drawtext ("mirror", 0,450 + 20, paint); // draw the gradient rectangle mpaint. setshader (mlineargradient3); canvas. drawrect (0,500,200,700, mpaint); canvas. drawtext ("repeat", 0,700 + 20, paint) ;}@ override P Ublic void run () {While (! Thread. currentthread (). isinterrupted () {try {thread. sleep (100);} catch (exception e) {thread. currentthread (). interrupt () ;}postinvalidate ();}}}


Lineargradient linear Rendering

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.