How Android uses images to populate path closed paths

Source: Internet
Author: User

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

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.