性能路径与许多rectF

时间:2018-12-15 08:06:56

标签: java android performance canvas kotlin

我需要在画布上绘制20 rectF。 哪种方法效果更好?

方法1:在画布上绘制每个rectF

 rectangleRectF.set(x1,y1,x2,y2)
 canvas.drawRect(rectangleRect,paint)

 rectangleRectF.set(x3,y3,x4,y4)
 canvas.drawRect(rectangleRect,paint)

 rectangleRectF.set(x5,y5,x6,y6)
 canvas.drawRect(rectangleRect,paint)

 rectangleRectF.set(x7,y7,x8,y8)
 canvas.drawRect(rectangleRect,paint)

方法2:在路径上添加rectF并在画布上绘制路径

rectangleRectF.set(x1,y1,x2,y2)
path.addRect(rectangleRectF)

rectangleRectF.set(x3,y3,x4,y4)
path.addRect(rectangleRectF)

rectangleRectF.set(x5,y5,x6,y6)
path.addRect(rectangleRectF)

rectangleRectF.set(x7,y7,x8,y8)
path.addRect(rectangleRectF)

canvas.drawPath(path,paint)

0 个答案:

没有答案