gpt4 book ai didi

java - 如何绘制路径并集的轮廓

转载 作者:搜寻专家 更新时间:2023-11-01 08:55:42 26 4
gpt4 key购买 nike

你好,我有一组六边形路径,想绘制这些路径的并集的轮廓(边界)。我想过使用 Region,将 Path 合并在一起,然后使用 getBoundaryPath() 获得边界结果 Path,但它什么也没画。那么有人能告诉我如何获得所有 Path 对象联合的轮廓(边界)吗?

 @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// if (pmBack != null) {
// canvas.drawBitmap(pmBack, new Matrix(), paint);
// }

if (mCells != null) {

for (int i = 0; i < mCells.length; i++) {
final HexCell cell = mCells[i];
if (cell != null) {
final PointF p = cell.getDrawPoint();
paint.setColor(cell.mColor);

Path path = drawHexagon(cell.mSize, mCenterX + p.x, mCenterY + p.y);
canvas.drawPath(drawHexagon(cell.mSize, mCenterX + p.x, mCenterY + p.y), paint);

if (i == 0) {
region.setPath(path, mClip);
} else {
region2.setPath(path, mClip);
region.op(region2, Op.UNION);
}
}
}
canvas.drawPath(region.getBoundaryPath(), paintContour);
}

}

private Path drawHexagon(final float size, float centerX, float centerY) {
Path path = new Path();
for (int i = 0; i <= 6; i++) {
double angle = 2 * Math.PI / 6 * (i + 0.5);
float x_i = (float) (centerX + size * Math.cos(angle));
float y_i = (float) (centerY + size * Math.sin(angle));
if (i == 0) {
path.moveTo(x_i, y_i);
} else {
path.lineTo(x_i, y_i);
}
}

return path;
}

最佳答案

尝试使用

Path outline = region.getBoundaryPath();
Path newpath = new Path();
Matrix matrix = new Matrix();
matrix.setScale(1, 1, 0, 0);
outline.transform(matrix,newpath);
canvas.drawPath(newpath, paint);

而不是直接使用 getBoundaryPath

关于java - 如何绘制路径并集的轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19115283/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com