|
1 | | -# Path之玩出花样 |
| 1 | +# Path之完结篇(伪) |
2 | 2 |
|
3 | 3 | ### 作者微博: [@GcsSloop](http://weibo.com/GcsSloop) |
4 | 4 | ### [【本系列相关文章】](https://github.com/GcsSloop/AndroidNote/tree/master/CustomView) |
5 | 5 |
|
6 | | -经历过前两篇 [Path之基本操作](https://github.com/GcsSloop/AndroidNote/blob/master/CustomView/Advance/%5B5%5DPath_Basic.md) 和 [Path之贝塞尔曲线](https://github.com/GcsSloop/AndroidNote/blob/master/CustomView/Advance/%5B6%5DPath_Bezier.md) 的讲解,本篇正式进入Path的收尾篇,通过使用前面的内容和本文新学的内容,教大家如何将玩转Path,玩出花样。 |
| 6 | +经历过前两篇 [Path之基本操作](https://github.com/GcsSloop/AndroidNote/blob/master/CustomView/Advance/%5B5%5DPath_Basic.md) 和 [Path之贝塞尔曲线](https://github.com/GcsSloop/AndroidNote/blob/master/CustomView/Advance/%5B6%5DPath_Bezier.md) 的讲解,本篇终于进入Path的收尾篇,本篇结束后Path的大部分相关方法都已经讲解完了,但Path还有一些更有意思的玩法,应该会在后续的文章中出现吧,嗯,应该会的ˊ_>ˋ |
7 | 7 |
|
8 | 8 | ****** |
9 | 9 |
|
@@ -282,50 +282,67 @@ XOR | 异或 | 包含Path1与Path2但不包括两者相交的部 |
282 | 282 |
|
283 | 283 | 代码: |
284 | 284 |
|
285 | | -``` |
286 | | - int x = 80; |
287 | | - int r = 100; |
288 | | - |
289 | | - canvas.translate(250,0); |
290 | | - |
291 | | - Path path1 = new Path(); |
292 | | - Path path2 = new Path(); |
293 | | - Path pathOpResult = new Path(); |
294 | | - |
295 | | - path1.addCircle(-x, 0, r, Path.Direction.CW); |
296 | | - path2.addCircle(x, 0, r, Path.Direction.CW); |
297 | | - |
298 | | - pathOpResult.op(path1,path2, Path.Op.DIFFERENCE); |
299 | | - canvas.translate(0, 200); |
300 | | - canvas.drawText("DIFFERENCE", 240,0,mDeafultPaint); |
301 | | - canvas.drawPath(pathOpResult,mDeafultPaint); |
302 | | - |
303 | | - pathOpResult.op(path1,path2, Path.Op.REVERSE_DIFFERENCE); |
304 | | - canvas.translate(0, 300); |
305 | | - canvas.drawText("REVERSE_DIFFERENCE", 240,0,mDeafultPaint); |
306 | | - canvas.drawPath(pathOpResult,mDeafultPaint); |
307 | | - |
308 | | - pathOpResult.op(path1,path2, Path.Op.INTERSECT); |
309 | | - canvas.translate(0, 300); |
310 | | - canvas.drawText("INTERSECT", 240,0,mDeafultPaint); |
311 | | - canvas.drawPath(pathOpResult,mDeafultPaint); |
312 | | - |
313 | | - pathOpResult.op(path1,path2, Path.Op.UNION); |
314 | | - canvas.translate(0, 300); |
315 | | - canvas.drawText("UNION", 240,0,mDeafultPaint); |
316 | | - canvas.drawPath(pathOpResult,mDeafultPaint); |
317 | | - |
318 | | - pathOpResult.op(path1,path2, Path.Op.XOR); |
319 | | - canvas.translate(0, 300); |
320 | | - canvas.drawText("XOR", 240,0,mDeafultPaint); |
321 | | - canvas.drawPath(pathOpResult,mDeafultPaint); |
| 285 | +``` java |
| 286 | + int x = 80; |
| 287 | + int r = 100; |
| 288 | +
|
| 289 | + canvas.translate(250,0); |
| 290 | +
|
| 291 | + Path path1 = new Path(); |
| 292 | + Path path2 = new Path(); |
| 293 | + Path pathOpResult = new Path(); |
| 294 | +
|
| 295 | + path1.addCircle(-x, 0, r, Path.Direction.CW); |
| 296 | + path2.addCircle(x, 0, r, Path.Direction.CW); |
| 297 | +
|
| 298 | + pathOpResult.op(path1,path2, Path.Op.DIFFERENCE); |
| 299 | + canvas.translate(0, 200); |
| 300 | + canvas.drawText("DIFFERENCE", 240,0,mDeafultPaint); |
| 301 | + canvas.drawPath(pathOpResult,mDeafultPaint); |
| 302 | +
|
| 303 | + pathOpResult.op(path1,path2, Path.Op.REVERSE_DIFFERENCE); |
| 304 | + canvas.translate(0, 300); |
| 305 | + canvas.drawText("REVERSE_DIFFERENCE", 240,0,mDeafultPaint); |
| 306 | + canvas.drawPath(pathOpResult,mDeafultPaint); |
| 307 | +
|
| 308 | + pathOpResult.op(path1,path2, Path.Op.INTERSECT); |
| 309 | + canvas.translate(0, 300); |
| 310 | + canvas.drawText("INTERSECT", 240,0,mDeafultPaint); |
| 311 | + canvas.drawPath(pathOpResult,mDeafultPaint); |
| 312 | +
|
| 313 | + pathOpResult.op(path1,path2, Path.Op.UNION); |
| 314 | + canvas.translate(0, 300); |
| 315 | + canvas.drawText("UNION", 240,0,mDeafultPaint); |
| 316 | + canvas.drawPath(pathOpResult,mDeafultPaint); |
| 317 | +
|
| 318 | + pathOpResult.op(path1,path2, Path.Op.XOR); |
| 319 | + canvas.translate(0, 300); |
| 320 | + canvas.drawText("XOR", 240,0,mDeafultPaint); |
| 321 | + canvas.drawPath(pathOpResult,mDeafultPaint); |
322 | 322 | ``` |
323 | 323 |
|
324 | 324 | ### 计算边界 |
325 | 325 |
|
326 | 326 | ### 重置路径 |
327 | 327 |
|
328 | 328 |
|
| 329 | +## About Me |
| 330 | + |
| 331 | +### 作者微博: [@GcsSloop](http://weibo.com/GcsSloop) |
| 332 | + |
| 333 | +<a href="https://github.com/GcsSloop/README/blob/master/README.md" target="_blank"> <img src="http://ww4.sinaimg.cn/large/005Xtdi2gw1f1qn89ihu3j315o0dwwjc.jpg" width=300 height=100 /> </a> |
| 334 | + |
| 335 | +## 参考资料 |
| 336 | +[Path](https://developer.android.com/reference/android/graphics/Path.html)<br/> |
| 337 | +[维基百科-Nonzero-rule](https://en.wikipedia.org/wiki/Nonzero-rule)<br/> |
| 338 | +[android绘图之Path总结](http://ghui.me/post/2015/10/android-graphics-path/)<br/> |
| 339 | +[]()<br/> |
| 340 | +[]()<br/> |
| 341 | +[]()<br/> |
| 342 | +[]()<br/> |
| 343 | +[]()<br/> |
| 344 | +[]()<br/> |
| 345 | + |
329 | 346 |
|
330 | 347 |
|
331 | 348 |
|
|
0 commit comments