To achieve a graffiti effect today, will be a few steps to achieve, here is an important point of knowledge is layer, to understand this, or you see this blog, very confused, confused boundless horizon is my love, first from the simple need to do, draw a line, the code is as follows:
Package Com.tuya;
Import Android.content.Context;
Import Android.graphics.Canvas;
Import Android.graphics.Paint;
Import Android.graphics.Path;
Import Android.util.AttributeSet;
Import android.view.MotionEvent;
Import Android.view.View;
/** * Created by admin on 2016/12/16.
* * public class Graffitiview extends view{private Paint Paint;
private path Path;
private float Downx,downy;
private float tempx,tempy;
Public Graffitiview {This (context,null);
Public Graffitiview (context, AttributeSet attrs) {This (context, attrs,0);
Public Graffitiview (context, AttributeSet attrs, int defstyleattr) {Super (context, attrs, defstyleattr);
Init ();
private void init () {paint = new paint ();
Paint.setantialias (TRUE);
Paint.setstrokewidth (10);
Paint.setstyle (Paint.Style.STROKE);
Path = new Path ();
} @Override protected void OnDraw (Canvas Canvas) {Super.ondraw (Canvas);
if (path!=null) { Canvas.drawpath (Path,paint); @Override public boolean ontouchevent (Motionevent event) {switch (event.getaction ()) {case Motioneven
T.action_down:downx = Event.getx ();
DownY = Event.gety ();
Path.moveto (Downx,downy);
Invalidate ();
TEMPX = Downx;
Tempy = DownY;
Break
Case MotionEvent.ACTION_MOVE:float MoveX = Event.getx ();
float Movey = event.gety ();
Path.quadto (Tempx,tempy,movex,movey);
Invalidate ();
TEMPX = MoveX;
Tempy = Movey;
Break
return true; }
}
Effect:
If you do not use the path Quadto () with the LineTo () method, but do not use queadto () to draw the smooth paths, these 5 paths are how to draw to the screen? The concept of the layer, if not understood, can go to see what I have written about Canvas blog, also can go to the Internet to see other blogs,
We know every time canvas.draw ... () actually produces new layers, only the layers are transparent, and finally insinuate to the canvas (canvas), the canvas is analyzed:
The above is a small set to introduce the Android use of path to achieve graffiti function, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!