当前位置:网站首页>Methods of path related comments (I)
Methods of path related comments (I)
2022-07-26 17:11:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack
The past is mainly about Canvas Of translate( translation ) 、scale( The zoom ) 、rotate( rotate ) 、skew( Crosscutting ). The next few articles are mainly about android Inside Path( Encapsulates the Bezier curve )& Canvas Inside drawPath(path,paint);
Many people hear Bezier curve , I think it seems to be quite high-end and elegant . I will unveil it with you later , See the truth ;
Path( route ):
Let's see Path What methods are there in the class
Let's look down :
There are two constructors . They are
/**
* Create an empty path
*/
public Path() {
mNativePath = init1();
mDetectSimplePaths = HardwareRenderer.isAvailable();
}and
/**
* Create a new path, copying the contents from the src path.
*
* @param src The path to copy from when initializing the new path
*/
public Path(Path src) {
int valNative = 0;
if (src != null) {
valNative = src.mNativePath;
}
mNativePath = init2(valNative);
mDetectSimplePaths = HardwareRenderer.isAvailable();
}There's nothing to say , The other is direct reuse src Create a new Path object .
path.reset(): Remove path Lines and curves in , But it won't change fill-type( Back setFillType Besides, );
path.rewind(): Remove path Lines and curves in , However, the internal data structure will be preserved for reuse ;
path.set(Path src); use src Replace the original with the content of path The content of , Let's look at a small sample :
Create a path, Add a solid circle to path in
mEndPath = new Path();
mEndPath.addCircle(300, 300, 100, Direction.CW);Draw the path:
canvas.drawPath(mEndPath, mPaint);The effect is as follows , it :
At this time in path Add a rectangle in :
mEndPath = new Path();
mEndPath.addCircle(300, 300, 100, Direction.CW);
mEndPath.addRect(new RectF(50, 50, 250, 200), Direction.CW);The effect is as follows :
Make the following modifications, for example :
mEndPath = new Path();
mEndPath.addCircle(300, 300, 100, Direction.CW);
//mEndPath.addRect(new RectF(50, 50, 250, 200), Direction.CW);
mSrcPath = new Path();
mSrcPath.addRect(new RectF(50, 50, 250, 200), Direction.CW);
mEndPath.set(mSrcPath);Direct execution , Suppose that 4.0 On the above machine (4.0 And above hardware acceleration is enabled by default ), You will find nothing on the screen , It shows that this method will be affected by hardware acceleration , Turn off hardware acceleration , Look at the effect again. :
Let's take a look Path Of FillType - Fill mode :
android There are four kinds of FillType, They are :
WINDING (0),
EVEN_ODD (1),
INVERSE_WINDING (2),
INVERSE_EVEN_ODD (3)
There is a diagram that can be used specifically to illustrate the differences between these four modes :
The above diagram is very clear , Let's use the following code for testing :
mEndPath = new Path();mEndPath.addCircle(300, 300, 150, Direction.CW);mEndPath.addCircle(380, 380, 150, Direction.CW);mEndPath.setFillType(FillType.INVERSE_EVEN_ODD);mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);mPaint.setStyle(Style.FILL);mPaint.setColor(Color.RED);The test results are shown in the following figure :
Not set up FillType:
setFillType(FillType.WINDING) setFillType(FillType.EVEN_ODD):
setFillType(FillType.INVERSE_WINDING): setFillType(FillType.INVERSE_EVEN_ODD):
According to the above figure ,Path Of FillType Be able to summarize the following :
1.Path Default FillType by FillType.WINDING;
2. The scope of action is to draw Path Of Canvas The overall . Instead of path Area ;
3.FillType.WINDING: take path All areas ;
4.FillType.EVEN_ODD: take path In areas that do not intersect ;
5.FillType.INVERSE_WINDING: take path All unoccupied areas ;
6.FillType.INVERSE_EVEN_ODD: take path Unoccupied or intersecting areas ;
Here are a few methods related to fill patterns :
getFillType(): Needless to say . return Path Fill patterns for ;
setFillType(): Set up Path Fill patterns for ;
isInverseFillType(): Whether it is The inverse Fill mode :
WINDING and EVEN_ODD return false,INVERSE_WINDING and INVERSE_EVEN_ODD return true.
toggleInverseFillType(): Switch the opposite fill mode . Take a small example :
mEndPath = new Path(); mEndPath.addCircle(300, 300, 150, Direction.CW); mEndPath.addCircle(380, 380, 150, Direction.CW); mEndPath.setFillType(FillType.WINDING); mEndPath.toggleInverseFillType(); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setStyle(Style.FILL); mPaint.setColor(Color.RED);Now give Path Set up WINDING Fill patterns for , call toggleInverseFillType(). The final pattern is :
FillType.INVERSE_WINDING
isEmpty():path Is it empty , hypothesis path It does not include any lines and curves , Then return to true, Otherwise return to false;
isRect(RectF rect): hypothesis path The designated one is rect, Then return to true, Otherwise return to false. Suppose we return to true & rect Not for null. Then the rect Set to path Region ;
computeBounds(RectF bounds,boolean exact): Calculation path Area , And write the result to bounds, Suppose the whole path Only include 0 or 1 A little bit , Will return (0,0,0,0):
Use the following code to test :
mComputeRect = new RectF(); mEndPath = new Path(); mEndPath.addCircle(380, 380, 150, Direction.CW); mEndPath.addRect(new RectF(200, 300, 500, 500), Direction.CW); mEndPath.computeBounds(mComputeRect, false); Toast.makeText( mContext, "" + mComputeRect.left + "," + mComputeRect.top + "," + mComputeRect.right + "," + mComputeRect.bottom, Toast.LENGTH_LONG).show();The return result is (200,230,530,530), namely path The boundary area of the content
incReserve(int extraPtCount): Tips path Will be added extraPtCount A little bit . This enables path Allocate its storage space efficiently .
Okay , This article mainly introduces these methods . The following is mainly about Path in XXXTo and addXXX Related methods , Finally, we'll use it together Path Make an example !
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117820.html Link to the original text :https://javaforall.cn
边栏推荐
- Wechat applet - network data request
- Response object - response character data
- Redis persistence - detailed analysis of RDB source code | nanny level analysis! The most complete network
- Execution process of select statement in MySQL
- Are CRM and ERP the same thing? What's the difference?
- 【开发教程7】疯壳·开源蓝牙心率防水运动手环-电容触摸
- [daily3] vgg16 learning
- Docker install redis? How to configure persistence policy?
- [basic course of flight control development 1] crazy shell · open source formation UAV GPIO (LED flight information light and signal light control)
- 搭建typora图床
猜你喜欢

别用Xshell了,试试这个更现代的终端连接工具

Take you a minute to learn about symmetric encryption and asymmetric encryption

Anaconda download and Spyder error reporting solution

Idea Alibaba cloud multi module deployment
It turns out that cappuccino information security association does this. Let's have a look.
![37. [categories of overloaded operators]](/img/67/b821270079589c53b9c38b0ca033ac.png)
37. [categories of overloaded operators]

Marxan模型保护区优化与保护空缺甄选技术、InVEST生态系统中的应用

Review the past and know the new MySQL isolation level

How to implement Devops with automation tools | including low code and Devops application practice

导数、微分、偏导数、全微分、方向导数、梯度的定义与关系
随机推荐
正则表达式
Thoroughly uncover how epoll realizes IO multiplexing
Oracle创建表分区后,查询的时候不给出partition,但是会给分区字段指定的值,会不会自动按照分区查询?
Sharing of 40 completed projects of high-quality information management specialty [source code + Thesis] (VI)
2022-2023 topic recommendation of information management graduation project
Marketing guide | several common micro blog marketing methods
Marxan模型保护区优化与保护空缺甄选技术、InVEST生态系统中的应用
Anaconda download and Spyder error reporting solution
[visdrone data set] yolov7 training visdrone data set and results
Speaker recruitment | AI time recruit icml/ijcai 2022 as a Chinese speaker!!!
Marxan model, reserve optimization and protection vacancy selection technology, application in invest ecosystem
Idea Alibaba cloud multi module deployment
【无标题】
Take you a minute to learn about symmetric encryption and asymmetric encryption
操作系统迁移实战之在openEuler上部署MySQL数据库
ES:Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes
2 - configuration and use of routes
Definition and relationship of derivative, differential, partial derivative, total derivative, directional derivative and gradient
In May, 2022, video user insight: user use time increased, and the platform achieved initial results in cost reduction and efficiency increase
Current limiting comparison: how to choose sentinel vs hystrix?