1

我写了一段代码并在android 4.0.3上测试过;一切正常。现在我在 android 4.2.2 上测试了它,填充方法不起作用。我已经简化了问题,这是一个显示真正问题的虚拟代码:

Paint testpaint = new Paint();
testpaint.setColor(Color.BLACK);
testpaint.setAlpha(255);
testpaint.setStyle(Paint.Style.FILL);

Path p = new Path();
p.moveTo(10, 10);
p.lineTo(200, 10);
p.lineTo(200, 250);
p.lineTo(10, 200);
p.lineTo(10,10);
p.close();

RectF rectF = new RectF();
Region rr = new Region();
p.computeBounds(rectF, false);
rr.setPath(p,new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));

//works
RegionIterator ri = new RegionIterator(rr);
Rect rect = new Rect();
int count = 0;
while (ri.next(rect)){
    canvas.drawRect(rect, testpaint);
    count++;
}

//works
canvas.drawPath(p, testpaint);

//doesn't work
canvas.drawPath(rr.getBoundaryPath(), testpaint);


//works
Path outline = rr.getBoundaryPath();
Path newpath = new Path();
Matrix matrix = new Matrix();
matrix.setScale(1, 1, 0, 0);
outline.transform(matrix,newpath);
canvas.drawPath(newpath, testpaint);

第一次和第二次抽签成功了,但第三次没有。如果我进行零旋转,那么它也可以。有谁知道为什么(我需要 getBoundaryPath 版本),为什么它在 4.0.3 上有效?

4

1 回答 1

-1

getBoundaryPath() returns bool as far as i know. Maybe try rr.boundaryPath which should return the path.

于 2014-05-04T09:17:21.877 回答