Canvas center image

Guys i need help. :slight_smile:
I have the bellow code to scale the image,but i can’t center it.

g.ForeColor= &cC2C2C200 g.DrawRect 0,0,Me.width,Me.height g.DrawPicture(External,0,0,64,64,0,0,512,512)
i have try this but no success g.DrawPicture(External,0,0,64-External.Width/2,64-External.Height/2,0,0,512,512)
Canvas size is 128x128

g.DrawPicture(External,      0,0,g.width,g.height,      0,0,External.Width,External.Height)

you should never hardcode size values for controls… because if they change (or you change them). then you have to hunt down all the places you need to modify…

the 2nd set of values are the ORIGINAL picture values
the 1st set are what you WANT it to be…

so this should take an image called “EXTERNAL” the has a given size (in your instance 512x512) and display it in a canvas of another size… in your case 64x64… but done right, we done care what the sizes are, we just know how we want the result manipulated.

there is no “centering” required, because you are just scaling the picture (up or down, it doesn’t matter)

Use something like this

dim X as integer = (g.width-64)/2 Dim y as integer = (g.height - 64)/2

Then use X and y for the second and third parameters.

Thank you @Greg O’Lone
and @Dave S