Android 4.2.2 Region.getBoundaryPath()绘图

时间:2013-06-20 20:52:47

标签: android drawing

我写了一个代码并在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上运行?

1 个答案:

答案 0 :(得分:-1)

据我所知,

getBoundaryPath()会返回bool。也许尝试rr.boundaryPath,它应该返回路径。