Just touched Android, recently in a small project, using path to draw a rectangle based on four point coordinates, you need to fill the rectangle with a picture. Because the rectangle that is drawn according to the path is inclined, it is not easy to fill the picture, after checking the data, through the experiment to obtain a method, share:
Draw a small wheat field code where four point coordinates are converted to screen coordinates according to latitude and longitude, so the little wheat field is not necessarily positive
Paint Mfield = new paint ();
Mfield.setantialias (TRUE);
Path Mfieldpath = new Path ();
Mfieldpath.moveto (X1,Y1);
Mfieldpath.lineto (X2,Y2);
Mfieldpath.lineto (X3,Y3);
Mfieldpath.lineto (X4,Y4);
Mfieldpath.close ();
MFIELD.SETARGB (200, 255, 215, 0);//Set the fill color of the closed path to gold * * *
Canvas.drawpath (Mfieldpath, Mfield);
So the drawing out of the graph for a gold * * * *, not beautiful enough, so think of using pictures to fill
Add the following code directly:
Shader Mshader = new Bitmapshader (fieldbitmap,shader.tilemode.repeat,shader.tilemode.mirror);
Mfield.setshader (Mshader);
Wherein, FILEDBITMAP for the specified picture, can be obtained by Mfieldbitmap = Bitmapfactory.decoderesource (This.getresources (), r.drawable.feild);
This article is from the "Smile" blog, make sure to keep this source http://xmrs2014.blog.51cto.com/9528128/1571843
How Android uses images to populate path closed paths