Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 4071

Scale and Center Backdrop on Canvas

$
0
0

I have the following code that works fine but always places the image in the top left corner.
// Calculate the scale ratio
Dim ratio As Double = min(maxHeight / p.height, maxWidth / p.width)

// Create a new picture to return
Dim newPic As New Picture(p.width * ratio, p.height * ratio)

// Draw picture in the new size
newPic.graphics.DrawPicture(p, 0, 0, newPic.width, newPic.height, 0, 0, p.width, p.height)

I tried changing to

// Draw picture in the new size
dim x as double = (maxWidth-newPic.Width)/2
dim y as double = (maxHeight-newPic.Height)/2
newPic.graphics.DrawPicture(p, x, y, newPic.width, newPic.height, 0, 0, p.width, p.height)

the picture gets shifted over some (not centered) and it crops off part of the right side. What am I doing wrong? MaxHeight and MaxWidth is the size of the canvas

7 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 4071

Trending Articles