Code check needed.

Hi,
I am really having trouble understanding the concept of this.

The code below is said to center an image in a canvas:
Where on earth is the width and height of the image called myImage defined in this code???

Dim p as Picture = new picture(Canvas1.Width, Canvas1.Height, 32) p.graphics.forecolor = &cFFFFFF p.graphics.rectfill(0,0,Canvas1.Width,Canvas1.Height) p.Graphics.DrawPicture (myImage, (Canvas1.Width/2)-(p.Width/2),(Canvas1.Height/2)-(p.Height/2))

Line 1 seems to create a picture object, the width and height of the canvas
Line 2 sets the forecolor
Line 3 creates a rectangle the same width and height of the canvas
Line 4 makes no sense to me - as p seems to be equal to the Canvas1 width and height???

Is this working code? Or is it just supposed to be working?

No idea if it works, as I am on my iPad and can’t test it.
I can’t see how it would work, because I cannot see where the image’s width and height are defined??

I think line 4 should probably read…

p.Graphics.DrawPicture (myImage, (Canvas1.Width/2)-(myImage.Width/2),(Canvas1.Height/2)-(myImage.Height/2))

or if you want to do it in less operations…

p.Graphics.DrawPicture (myImage, (Canvas1.Width-myImage.Width)/2,(Canvas1.Height-myImage.Height)/2)

Thanks Alwyn - I thought I was going mad for a moment.
I also thought that line 4 should be as you advise - but as a novice, I often find out that my ideas are wrong, so I thought I would check first :slight_smile:

Thank you.