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