Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取区域的轮廓_Java_Awt - Fatal编程技术网

Java 获取区域的轮廓

Java 获取区域的轮廓,java,awt,Java,Awt,有一个中空的Java.awt.geom.Area,我怎样才能得到该区域的轮廓? e、 g 愚蠢的方式: static public Area getOutline(Area area) { Area ret = new Area(); double[] coords = new double[6]; GeneralPath tmpPath = new GeneralPath(); PathIterator pathIterator = area.getPathI

有一个中空的
Java.awt.geom.Area
,我怎样才能得到该区域的轮廓? e、 g

愚蠢的方式:

static public Area getOutline(Area area) {
    Area ret = new Area();
    double[] coords = new double[6];
    GeneralPath tmpPath = new GeneralPath();

    PathIterator pathIterator = area.getPathIterator(null);
    for ( ; !pathIterator.isDone(); pathIterator.next() ) {
        int type = pathIterator.currentSegment(coords);
        switch (type) {
        case PathIterator.WIND_EVEN_ODD:
            tmpPath.reset();
            tmpPath.moveTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_LINETO:
            tmpPath.lineTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_QUADTO:
            tmpPath.quadTo(coords[0], coords[1], coords[2], coords[3]);
            break;
        case PathIterator.SEG_CUBICTO:
            tmpPath.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
            break;
        case PathIterator.SEG_CLOSE:
            ret.add(new Area(tmpPath));
            break;
        default:
            System.err.println("Unhandled type " + type);
            break;
        }
    }

    return ret;
}
static public Area getOutline(Area area) {
    Area ret = new Area();
    double[] coords = new double[6];
    GeneralPath tmpPath = new GeneralPath();

    PathIterator pathIterator = area.getPathIterator(null);
    for ( ; !pathIterator.isDone(); pathIterator.next() ) {
        int type = pathIterator.currentSegment(coords);
        switch (type) {
        case PathIterator.WIND_EVEN_ODD:
            tmpPath.reset();
            tmpPath.moveTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_LINETO:
            tmpPath.lineTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_QUADTO:
            tmpPath.quadTo(coords[0], coords[1], coords[2], coords[3]);
            break;
        case PathIterator.SEG_CUBICTO:
            tmpPath.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
            break;
        case PathIterator.SEG_CLOSE:
            ret.add(new Area(tmpPath));
            break;
        default:
            System.err.println("Unhandled type " + type);
            break;
        }
    }

    return ret;
}