Build an ImageSet on the fly?

Hi, does anyone know if it is possible to build an ImageSet on the fly in code at runtime from 3 different png pictures? I currently have them statically assigned in the IDE before the build, but I would like to add more flexibility in which png files go with each ImageSet. I have tried all kinds of ways to assign them, but no luck. I can access the individual .png pictures using MyImageSet.ImageAt(x), but can’t find a way to change them or build an ImageSet from scratch.

From the various posts here on ImageSets, I am starting to think it is not possible. If anyone has done this, could you provide some guidance?

Thanks

You would use the Picture constructor that takes an array of Picture as the last parameter.

Hi Anthony, thanks for the response. I tried that after reading it in another post, but could not get it to work. I had set up the array of pics, but could not get it to accept it for reason. Do you have a line of code I could see, I am sure I am messing it up somewhere in the syntax.

Sure thing. Put this anywhere, and inspect the variables in the debugger:

'// Create three picture for different scales.
var p1 as new Picture( 100, 100 )
p1.Graphics.DrawingColor = &cff0000
p1.Graphics.FillRectangle( 0, 0, p1.Width, p1.Height )

var p2 as new Picture( 200, 200 )
p2.Graphics.DrawingColor = &c00ff00
p2.Graphics.FillRectangle( 0, 0, p2.Width, p2.Height )

var p3 as new Picture( 300, 300 )
p3.Graphics.DrawingColor = &c0000ff
p3.Graphics.FillRectangle( 0, 0, p3.Width, p3.Height )

'// Create the new Picture object containing our child images
var myPicture as new Picture( 100, 100, Array( p1, p2, p3 ) )

'// Get the first picture in the object.
var firstImage as Picture = myPicture.ImageAt( 0 )

'// Get the image that best matches the specified criteria
var bestRep as Picture = myPicture.BestRepresentation( 100, 100, 2 )
break

OK, thank you, I will try this first thing in the morning, Way past the time I should be coding! I am sure I can get it from here, I think the problem is in the way I am passing in the pics array in the constructor. Thanks again!

Happy to help!

Couldn’t resist, had to try it, before going to bed. Got it to work, I was trying to pass MyPics() as the last parameter, instead of Array(p1, p2, p3) as you did. Worked great, thank you!

Glad to hear it! Please be sure to mark the solution so that others can see it more readily if they stumble across this in the future.

Just did, thanks again for the help. Have a great weekend!

1 Like
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.