# Draw Picture Inside RoundRect.

I’m trying to draw a round rectangle in the center of a canvas and then draw a picture centered inside of the rectangle. How do I get a reference to the width and height of the rectangle so I can use it in drawpicture? Thanks.

[code] dim p as picture

g.ForeColor = &c80000000
g.FillRoundRect(Canvas2.Width /2 - p.Width /2, Canvas2.Height /2 - p.Height /2, p.width+50, p.height+50, 10, 10)

’ How do I do something like this?
g.DrawPicture(p, g.FillRoundRect.Width /2 - p.Width /2, g.FillRoundRect.Height /2 - p.Height /2)[/code]

To draw the roundrect don’t you need to know it’s positioning?
I mean you could probably create a class so you have access to an object, but I think you’re over-complicating things.

It looks like you’re already centering the roundrect, so you would just need to center the inner picture too.

``````dim p as picture /// THIS IS NEVER POPULATED
dim x as integer=Canvas2.Width /2 - p.Width /2
dim y as integer=Canvas2.Height /2 - p.Height /2
dim w as integer=p.width+50
dim h as integer=p.height+50
g.ForeColor = &c80000000
g.FillRoundRect(x, y, w, h, 10, 10)

' How do I do something like this?
g.DrawPicture(p, x, y)
``````

and where does “P” get defined???

but this does not do TWO things

• insure that “P” is scaled, or fits inside the define area (your draw picture has no scaling information)
• does not CLIP the rounded corners of “P” … since the draw picture comes AFTER the rectangle, the square corners of the picture will obsuure you fill area.

maybe something like

``g.drawpicture(p,x+10,y+10, w-20,h-20, 0,0,p.width,p.height)``

Thanks for the replies!

Dave I will give this a try!

p gets defined somewhere else, I just put that dim in the example code.

I finally got something working but I’m not sure I like it. I scale the picture to the size I want and then use the picture to draw a rounded rectangle in the center of the canvas. Then I scale the picture again a little smaller and draw it to the center of the canvas which gives me the desired result.

[code]
pUser = ScaleImage(pOriginal, 500, 500)

g.ForeColor = &c80000000
g.FillRoundRect(me.Width /2 - pUser.Width /2, me.Height /2 - pUser.Height /2, pUser.width, pUser.height, 10, 10)

``````p = ScaleImage(pUser, 475, 475)
g.DrawPicture(p, me.Width /2 - p.Width /2, me.Height /2 - p.Height /2)[/code]``````

There are lots of ways you can do this, but you just need to keep track of the sizes you want to use and do the math.

Something like this will draw a RoundRect to fit into the Canvas area and then will draw a picture (scaling if necessary) to fit into the RoundRect.

``````    Dim p As picture = SeaSlug

Const kBorder = 10
g.ForeColor = &c80000000

// Draw a RoundRect to fit within the size of the Canvas, subtracting a border value
Dim rrWidth As Integer = g.Width - kBorder * 2
Dim rrHeight As Integer = g.Height - kBorder * 2

Const kPicBorder = 50
Dim picWidth As Integer = rrWidth - kPicBorder * 2
Dim picHeight As Integer = rrHeight - kPicBorder * 2

g.FillRoundRect((g.Width - rrWidth) / 2, (g.Height - rrHeight) / 2, rrWidth, rrHeight, 10, 10)
g.DrawPicture(p, (g.Width - picWidth) / 2, (g.Height - picHeight) / 2, picWidth, picHeight, _
0, 0, p.Width, p.Height)``````

Thanks Paul! Both answers helped so thanks again!

[quote=298378:@Dave S][code]
dim p as picture /// THIS IS NEVER POPULATED
dim x as integer=Canvas2.Width /2 - p.Width /2
dim y as integer=Canvas2.Height /2 - p.Height /2
dim w as integer=p.width+50
dim h as integer=p.height+50
g.ForeColor = &c80000000
g.FillRoundRect(x, y, w, h, 10, 10)

’ How do I do something like this?
g.DrawPicture(p, x, y)

[/code]

and where does “P” get defined???

but this does not do TWO things

• insure that “P” is scaled, or fits inside the define area (your draw picture has no scaling information)
• does not CLIP the rounded corners of “P” … since the draw picture comes AFTER the rectangle, the square corners of the picture will obsuure you fill area.

maybe something like

``g.drawpicture(p,x+10,y+10, w-20,h-20, 0,0,p.width,p.height)``

[quote=298388:@Paul Lefebvre]There are lots of ways you can do this, but you just need to keep track of the sizes you want to use and do the math.

Something like this will draw a RoundRect to fit into the Canvas area and then will draw a picture (scaling if necessary) to fit into the RoundRect.

[code]
Dim p As picture = SeaSlug

``````Const kBorder = 10
g.ForeColor = &c80000000

// Draw a RoundRect to fit within the size of the Canvas, subtracting a border value
Dim rrWidth As Integer = g.Width - kBorder * 2
Dim rrHeight As Integer = g.Height - kBorder * 2

Const kPicBorder = 50
Dim picWidth As Integer = rrWidth - kPicBorder * 2
Dim picHeight As Integer = rrHeight - kPicBorder * 2

g.FillRoundRect((g.Width - rrWidth) / 2, (g.Height - rrHeight) / 2, rrWidth, rrHeight, 10, 10)
g.DrawPicture(p, (g.Width - picWidth) / 2, (g.Height - picHeight) / 2, picWidth, picHeight, _
0, 0, p.Width, p.Height)
``````

[/code][/quote]