2

您好,我有一包六边形路径,并且想要绘制这些路径联合的轮廓(边框)。我想过使用区域,将路径联合在一起,然后使用 getBoundaryPath() 获取边界结果路径,但它什么也没画。那么有人可以告诉我如何获得所有路径对象的联合的轮廓(边框)吗?

 @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;
}
4

1 回答 1

3

尝试使用

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

于 2014-03-28T15:44:31.590 回答