当前位置:网站首页>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
边栏推荐
- ES:Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes
- My meeting of OA project (meeting seating & submission for approval)
- UPC 2022 summer personal training game 07 (part)
- Alibaba Cloud Toolkit —— 项目一键部署工具
- Xiaomi Wuhan headquarters building starts today! Lei Jun: planned according to the scale of 10000 people
- [Luogu p8063] shortest paths (graph theory)
- 操作系统迁移实战之在openEuler上部署MySQL数据库
- MySQL lock mechanism (example)
- 抓包与发流软件与网络诊断
- [express receives get, post, and route request parameters]
猜你喜欢

如何借助自动化工具落地DevOps|含低代码与DevOps应用实践

Packet capturing and streaming software and network diagnosis

FIR filter design

Relationship between standardization, normalization and regularization

Realizing DDD based on ABP -- related concepts of DDD

Small application of C language using structure to simulate election

How to write unit tests
![[ctfshow web] deserialization](/img/cd/b76e148adfc4d61049ab2cf429d4d7.png)
[ctfshow web] deserialization

How does the data link layer transmit data

Current limiting comparison: how to choose sentinel vs hystrix?
随机推荐
[express receives get, post, and route request parameters]
Merge multiple row headers based on apache.poi operation
2022-2023 topic recommendation of information management graduation project
Pyqt5 rapid development and practice 3.2 introduction to layout management and 3.3 practical application of QT Designer
限流对比:Sentinel vs Hystrix 到底怎么选?
Win11怎么自动清理回收站?
【飞控开发基础教程3】疯壳·开源编队无人机-串口(基础收发)
Tensorflow Lite source code analysis
How does win11 reinstall the system?
Docker install redis? How to configure persistence policy?
快速学会配置yum的本地源和网络源,并学会yum的使用
Matlab论文插图绘制模板第40期—带偏移扇区的饼图
Nacos win10 installation and configuration tutorial
Stop using xshell and try this more modern terminal connection tool
第一章概述-------第一节--1.3互联网的组成
“青出于蓝胜于蓝”,为何藏宝计划(TPC)是持币生息最后的一朵白莲花
[development tutorial 8] crazy shell · open source Bluetooth heart rate waterproof sports Bracelet - triaxial meter pace
接口比较器
Operating system migration practice: deploying MySQL database on openeuler
Are CRM and ERP the same thing? What's the difference?