Android Question Drawing a rectangle

scGuy

Member
Licensed User
I'm a bit new here, and may be missing something obvious. I have a panel, create a ColorDrawable object, initialize a canvas object. Now I want to do some basic free-hand drawing. I see I can do lines, circles, ovals, etc... but when it comes to drawing a simple rectangle, why is another object required?

In the canvas object, the DrawRect method expects a Rect object. But DrawLine and DrawCircle simply do the drawing. Am I missing an obvious way to draw a rectangle without using a Rect object?

Thanks!
 

Jeffrey Cameron

Well-Known Member
Licensed User
The rect object provides more utility than a simple parameter list-- as well as simplifiing the call's parameter list. For example, you can specify ending x/y or width/height by working with the rect object's methods. Calls such as DrawBitmap that take multiple rect's would be quite cluttered to read if you had to pass each individual coordinate pair.

Without a rect, the various methods would be forced to require either ending x/y or the width/height or have a .DrawRect2 overload, etc. You can always make your own DrawRect method with static parameters if that is more to your liking.
 
Upvote 0

scGuy

Member
Licensed User
Ok, maybe my question is more along the lines of... is there a hidden cost, or performance issues, to creating a lot of Rect objects to get a job done? Imagine a hypothetical scenario where I need to build some graphic using a hundred rectangles... would calling:

Dim r as Rect
r.Initialize( ...etc... )
someCanvas.DrawRect( etc )

...over and over again cause issues?

Thanks again
 
Upvote 0
Top