Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I iterate over android.graphics.Path segments?

I have an android Path object (created from text: paint.getTextPath(someString, 0, someString.length(), 0f, 0f, myPathObject);)

How can I iterate over path object segments ("move to", "line to", "quad to", etc...) like with PathIterator in awt?

like image 322
lukaville Avatar asked Jun 05 '26 04:06

lukaville


1 Answers

Old question but I wanted it to have the answer Look at android.graphics.PathMeasure API 1

  float[] tmpPos = new float[2];
  float[] tmpTan = new float[2];
  PathMeasure measure = new PathMeasure();
  measure.setPath(path, true);
  do {
   float dist = measure.getLength();
   for (float p = 0; p < dist; p += 1) {
     measure.getPosTan(p, tmpPos, tmpTan);
     float x = tmpPos[0], y = tmpPos[1];
     float nx = tmpTan[0], ny = tmpTan[1];
     // do your own stuff
    }
 } while (measure.nextContour());
like image 184
hoford Avatar answered Jun 06 '26 17:06

hoford