RGBSurface is Nil

Pictures loaded with Picture.Open are also now immutable. As a result, the RGBSurface and Graphics objects are now nil. – Greg O’Lone

Mac Xojo 2021 R3.1

I suspect that the O’Lone quote I grabbed off the forum is relevant, but I am not sure how to proceed.

I am trying to analyze the pixels in a JPEG that I have as a file on my Mac. I can load the JPEG into a picture variable (myPict) and I can draw it onto a Canvas (myCanvas) in the Paint event of myCanvas.

g.DrawPicture(myPict, 50, 50). That works fine and I can see the picture.

However,

Var surf As RGBSurface = Self.myPict.RGBSurface

creates a surf with a value of Nil. So I cannot get the values of the individual pixels in the picture which is the goal.

I can create another Picture variable

Var anotherPic As New Picture(300,300)

anotherPic will have a non-Nil RGBSurface. I can Paint myPIct on to anotherPic

anotherPic.Graphics.DrawPicture(myPict, 0, 0)

And it will be visible but it does not register on the RGBSurface of anotherPic. The values returned from surf will ignore the pixels of the Picture.

What is the correct procedure to get a picture from disk and analyze its pixels? I want to be able to read the RGB values of various pixels in the Picture and then change other pixels in the same Picture. I don’t see how I can do this without an RGBSurface and I do not know how to get an RGBSurface of a picture that I have gotten from disk.

I do not want a reference to the picture on disk. I want a copy of that picture that I can fool around with.

Uh… that can’t be. DrawPicture applies the pixels from one pic to another. There’s no such thing as layers in Xojo’s picture class.

Well, I am not sure what I was doing wrong when I drew my conclusion, but not too surprising, Greg is correct. I must have simply been drawing the picture without a RGBSurface on top of the picture which had an RGBSurface. When I “read” the pixels, I simply got the pixels of the underneath picture and – its pixel values.
The solution to my overall problem was to assign the picture on the disk that I opened to a picture variable. That picture has no RGBSurface (It is Nil) so I can’t do anything with it.). But I created picture in the Opening event of the window and that picture does have an RGBSurface. Then the key line of code that I needed:

Self.picWithSurf.Graphics.DrawPicture(Self.picFromDisk, 50, 50)

That puts the picture that I want to analyze in a picture that has an RGBSurface and I have what I need.