Java examples for 2D Graphics:Path
reverse Path
//package com.java2s; import java.awt.geom.PathIterator; import java.awt.geom.GeneralPath; public class Main { public static GeneralPath reversePath(GeneralPath path) { GeneralPath newPath = new GeneralPath(GeneralPath.WIND_EVEN_ODD); int numOfLinePoints = getNumPathPoints(path); double seg[] = new double[6]; for (int i = numOfLinePoints; i > 0; i--) { final PathIterator pi2 = path.getPathIterator(null); for (int j = 0; j < (i - 1); j++) { pi2.next();// w w w. j a va 2 s.c o m } int segType = pi2.currentSegment(seg); if (i == numOfLinePoints) { newPath.moveTo((int) seg[0], (int) seg[1]); } else { newPath.lineTo((int) seg[0], (int) seg[1]); } } return newPath; } /** returns the number path points of "path". */ public static int getNumPathPoints(GeneralPath path) { int count = 0; for (PathIterator i = path.getPathIterator(null); !i.isDone(); i .next()) { count++; } return count; } }