Image_Pict.Graphics is Nil

The code below result in Image_Pict.Graphics = Nil.

Because I do not know the image size, I use this construction.


Dim Image_Pict As Picture

Image_Pict = Picture.Open(Open_FI)

QuestionMissingException!

I think if you use a current version of Xojo, you cannot draw on the picture’s graphics property.
You need to create a new picture of the same size in memory, and draw the loaded picture to that.
Mutable versus immutable. This is to make life easier ,apparently.

You might also check out Picture.CopyColorChannels () As Picture

Thank you for the advice.

On a M1 MacBook Pro, I cannot use old Xojo, so I run 2021r2.1 to test ideas, then back home I use 2015r1 on my Intel MacPro.

The problem is I always search how to do things; I’d better stop since this is a waste of time and wrote the idea in a text file, then back home, implement the idea.

For the record:

a night after the first attempt and I recall I already follow that path and the solution is:


Dim Source_Pict As Picture
Dim Image_Pict As Picture

// Load the image (to get the image size)
Source_Pict = Picture.Open(Open_FI)

// Create a working Picture (with Graphics)
Image_Pict = New Picture(Source_Pict.Width, Source_Pict.Height)
Image_Pict = Picture.Open(Open_FI)

// No more needed, so I delete it
Source_Pict = Nil

Source_Pict is a temporary used Picture; its purpose is to gives me the loaded image width and height. It can be set to Nil.

That is what I wanted to do:

The image on disk is 65 × 69 @ 144 dpi.