Populate images in a Canvas

Hi,

I have to show a list of images into a canvas. I have loaded the images into image variable(Picture type). After that, I use the Paint method into a Canvas to show the images. I make sure each image is not nil.

If Self.p0 <> Nil Then
g.DrawPicture(Self.p0, 0,0,72,100)
/End If

If Self.p1 <> Nil Then
g.DrawPicture(Self.p1, 74,74,72,100)
End If

It does not work the proper way. I have 5 images to show. If I try to show 2 images, it works. If I try to show 3 images, it shows the last one, If I try to show 4 images, it shows the third and the fourth one,

It seems bizarre the way it works. Probably, I do not do it the proper way.

Thanks for help,
Claude

You are using some of the extra parameters to DrawPicture, but not all of them. You should use all the extra parameters or none of them. How big is your canvas? What is the rest of the code when you have 4 or 5 images? And did you intend to tile them diagonally down the canvas?

Once you get this working, you should switch to using an array of images instead of separate properties. Also, “Self” is not required here. You can reference p0, p1, etc. directly.

[quote=83986:@Claude St-Pierre]If Self.p0 <> Nil Then
g.DrawPicture(Self.p0, 0,0,72,100)
/End If

If Self.p1 <> Nil Then
g.DrawPicture(Self.p1, 74,74,72,100)
End If[/quote]

Tim is spot on (once again) with adding your pictures to a picture array and searching through that. I also would not suggest using “some” of the resizing/cropping options unless you use all of them purposely. Are you trying to stack these side by side?

If Self.p0 <> Nil Then
g.DrawPicture(Self.p0, 0,50)
End If

If Self.p1 <> Nil Then
g.DrawPicture(Self.p1,74,50)
End If

If Self.p2 <> Nil Then
g.DrawPicture(Self.p2,148,50)
End If

If Self.p3 <> Nil Then
g.DrawPicture(Self.p3,222,50)
End If

You are using some of the extra parameters to DrawPicture, but not all of them. You should use all the extra parameters or none of them.

For the extra parameters, it is mostly used for scaling. For the moment, I only want to display images.

How big is your canvas? width = 450, height=324
I would like to show 8 images.

What is the rest of the code when you have 4 or 5 images? And did you intend to tile them diagonally down the canvas?
The rest of the code is the same for all other images. I would like to show 8 images: four on first row and four on second row.

Thanks again for help. I will try the array of images if it works better.