Creating a Picture Programmatically

Yes, this is an extension of my previous colorization question.

I want to create a blank picture object, draw into it, and display it in a canvas. I want to do this to make zooming, scrolling, and saving easier. But, here, my lack of OOP understanding really hits me in the face.

If I add a picture object, which I name MyPic, into the window’s property list (by dragging from the library pane), then try to reference it in the Window’s Open Event, I get a nil object exception. If I try to “new” it or set its width (as in MyPic.width = 2000), I get a “naughty boy, cannot do that” alert. I can create a local picture in the window open event and assign it to the canvas.backdrop but that does now allow scrolling.

I seem to be missing something critical, here. I have been trying to follow the canvas zoom and canvas scroll examples but those are for an existing picture. I am at a loss to deal with a picture that I have created on the fly.

Some hints would really be appreciated.

As a side note, when I try to open those examples in the current Xojo release, many of the properties are highlighted in red. I assume that these represent things that have changed since the example is created. But, I have no idea what to do about them (some are ordinary integers and would not seem to be candidate for update).

Thanks

Jim Wagner
Oregon Research Electronics

Create a property of type Picture. It will initially be nil. Assign a picture object to it via New Picture(Width, Height, Depth).

thePicture = New Picture(1000, 3000, 32)

There is, of course, a practical limit to the size of the picture. But that should get you started.

Thought I tried that but will do it again. I think I had problems when it was a window property, rather than a local (to the Open Event). But, will try again.

Thanks
Jim

You can’t do it if you dragged it into the project, but there shouldn’t be any problem with it being a window property. You will have problems if you make it local to the event, however.

Finally got it. I looks just like I THOUGHT I did however,I had copied that code block from one of the examples and may have forgotten to remove the declare from the line.

Thanks for the nudge,
Jim