Is android.graphics.Paint
memory heavy object? Which one is more efficient, to pass paint object refrence to classes that need to draw on canvas and set paint properties such as color, style, etc. in those classes, or create new Paint object wherever it's needed?
Yes, Paint
is heavy, especially its creation and initialization. Does this mean you have to reuse the same Paint
object for everything? Well, it depends.
If you are going to perform multiple drawText()
but with different color, then you can reuse the same paint but with different color (using setColor()
). But if you are going to perform two unrelated operation(drawing) in two different classes and there are major differences in the Paint configuration like Color, font size, Style, PathEffect, etc... then it's better to have separate Paint objects for them.
In short, use the same paint for performing similar drawing with less differences. And use different paint objects for performing unrelated drawing with major differences. Hope this helps.