android - 如何在不填充孔的情况下填充包含孔的 Android 路径?

标签 android graphics

我目前正在为 Android(API 级别 7)编写非常简单的游戏,以发现和学习 Android SDK。这个游戏涉及在屏幕上绘制形状,触摸时会改变颜色。

有些形状可能嵌入一个或多个孔。我的问题是:如果我触摸形状,整个东西的颜色都会改变,甚至是孔洞。这是我使用的伪代码,形状是我要绘制的多边形,边界是外边界,孔是孔的数组。孔和边界包含它们的点数组。

Path MyPath = Path();
Path.moveTo(boundary.points[0].x, boundary.point[0].x);
for (point in boundary) {
  MyPath.lineTo(point.x, point.y);
}
Path.close();

for (hole in shape.holes) {
  MyPath.moveTo(hole.points[0].x,hole.points[0].y);
  for (point in hole) {
    MyPath.lineTo(point.x, point.y);
  }
  MyPath.close();
}

// setting Paint here...
canvas.drawPath(MyPath, MyPaint);

关于 Android 中的路径,我缺少什么吗?或者您有其他替代方法吗?

最佳答案

您确定您使用的是正确的路径填充规则吗?例如,如果您使用 WINDING 作为填充规则,则孔必须相对于外边界处于相反的方向(例如逆时针边界和顺时针方向的孔)

关于android - 如何在不填充孔的情况下填充包含孔的 Android 路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4984308/

相关文章:

java - 安卓绘图程序

android:如何将具有共享用户标识的应用程序更新为没有共享用户标识的版本

C++ DirectX CreateDevice 从全窗口游戏

graphics - 光线追踪中的区域照明

java - 在 Java 中绘制圆弧

android - 带有 Flutter 的商米 V2

android - 将recyclerview放在其他Listview中

android - 在 Scala 和 Gradle 中使用 AndroidAnnotations

Android 开发 - 带鸟瞰图的 2D map

c - 图像抖动 : How would I calculate quantization error and nearest colour to implement in a Floyd-Steinburg algorithm?