绘制路径与孔(机器人) [英] draw path with hole ( android )

查看:147
本文介绍了绘制路径与孔(机器人)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有一个提示为我以下的问题?

Does anyone have a hint for me for the following problem ?

我想绘制填充路径(画布),其有一个洞。 在SVG路径定义为如下:

I would like to draw a filled path ( canvas ) which has a hole in it. In SVG the path definition is the follow :

M 100 100 L 200 100 L 200 200 L 100 200 L 100 100 z
M 125 125 L 175 125 L 175 175 L 125 175 L 125 125 z

我想得出这样的路径(形状)不带路径减去路径(因为特定的软件设计)

I would like to draw this path ( shape ) without path subtract path ( because of specific software design )

我用java尝试吸引了我一个完整方没有一个洞。我很纳闷,为什么SVG查看器绘制孔与mentoined定义和Java画布不?哪里是区别?我怎样才能做到这一点?

My try with java draws me a full square without a hole. I am wondering, why an SVG viewer draws the hole with the mentoined definition and the java canvas doesn't ? where is the difference ? How can I achieve this ?

            Path p=new Path();
        p.moveTo(100, 100);
        p.lineTo(200,100);
        p.lineTo(200,200);
        p.lineTo(100,200);
        p.close();
        p.moveTo(150, 150);
        p.moveTo(180, 150);
        p.moveTo(180, 180);
        p.moveTo(150, 180);
        p.close();
        canvas.drawPath(p, paint);

任何线索?

关于

推荐答案

您应该使用 Path.setFillType(Path.FillType.EVEN_ODD)

final Path path = new Path();
final Paint paint = new Paint();

paint.setColor(Color.RED);
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL_AND_STROKE);

path.moveTo(100, 100);
path.lineTo(200, 100);
path.lineTo(200, 200);
path.lineTo(100, 200);
path.close();

path.moveTo(150, 150);
path.lineTo(180, 150);
path.lineTo(180, 180);
path.lineTo(150, 180);
path.close();

path.setFillType(Path.FillType.EVEN_ODD);
canvas.drawPath(path, paint);

这篇关于绘制路径与孔(机器人)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆