Object2d to picture to working as documented nil HE

Greetings,

I need to convert an object2d to a picture to examine pixels. The documentation does not do as advertised.

//SavePicture is a picture property of the window
Var r As New RoundRectShape
r.Width = 120
r.Height = 120
r.Border = 100
r.BorderColor = Color.RGB(0, 0, 0) // black
r.FillColor = Color.RGB(255, 102, 102)
r.CornerHeight = 15
r.CornerWidth = 15
r.BorderWidth = 2.5

SavePicture.Graphics.DrawObject(r, 100, 100)
g.DrawPicture(savePicture, 0,0) // Draw SavePicture in the Canvas

I get a nil handle exception
Have tried other X,Y offsets

Please advise,

Thank you very much!

CG

How do you initialise SavePicture?
Which line gets Nil handle?
Is this in a Paint() event?

create a picture and use it .Graphics property (object) to paint/draw into.

Jeff,

2nd to last line:
aPicture.Graphics.DrawObject(r, 200, 200)

Thanks for asking.

Carl

Yes it is in the paint event

CG

It looks like you didn’t initialise SavePicture, so it is nil at that point.

As Jeff said:

1 Like

Var SavePicture As New Picture 500,500,0)

More information here.

by default object properties are nil / null
you can use a window event to init it once
Self.SavePicture = New Picture(500,500)

if you want to have the paint event output use
Paint(g as Graphics)
DrawSomething(g)

method DrawSomething(g as Graphics)
draw what you like

to have a copy call
DrawSomething(SavePicture.Graphics)

Look at the current documentation: the examples says 500,50,0 (zero, noit 32). Link in my post.

the docu :slight_smile:
Ashampoo_Snap_Mittwoch, 22. Februar 2023_12h40m25s_001_Picture � Xojo documentation � Mozilla Firefox

You are correct, just read below (or use the link above):

1 Like

Also, your screen shot is for older documentation. The current entry for Graphics is:

I included the URL bar.

Greetings, thank you for responding. I have instantiated a picture. Still nothing. Please see screen shots. I have studied the lastest documentation. Search “you should draw”.

Thanks for taking time to take a look.

Carl
Screen Shot 2023-02-22 at 4.43.37 PM

Jeff, the first to line are superfluous. I was testing to see if I really got a picture from 2d-object.

CG

OK: first issue…
A picture instantiated in this way has no Graphics property… it is nil
Hence the nilobject exception later

aPicture can be used to save a vector image. (in theory… never managed to find a use for one since Apple canned its vector image format)

The Objects property is essentially a Group2D

So this is me testing that…

What you see in the debugger is the contents of SecondPic

Also, I believe if you do

Var aPicture As New picture(10, 10, 0)

you are creating another property and not using the Window property ‘aPicture’.

You have “aPicture As Picture” on your Window1 scope so then you do:

aPicture = New Picture(100, 100) // 100 width, 100 height

If you only need it to be in the paint event then do it locally scoped:

Var aPicture As New Picture(100, 100) // 100 width, 100 height

But don’t do both with the same name.

There is no need for the 3rd parameter (depth) if you don’t need that.

My post above explains the difference between using a third parameter or not.
If it is 0, you indicate you want a vector image format.

But this post has dragged on a while.

Carl: if you want to just SEE what the object2d contains, then in the Paint event, forget the pictures.

All you need is


Var r As New RoundRectShape
r.Width = 120
//blah blah
r.BorderWidth = 2.5

g.DrawObject(r, 0,0) // Draw SavePicture in the paint event

if you want to have more than one Object2d, create a Group2d object, and append the shapes to that, then draw the Group2D instead of all the Object2Ds

if you want to try saving as a vector image, thats the point where you create a picture with a depth of 0, and assign the Group2d Object to the picture’s Objects property, or append the individual Object2Ds to it instead of your Group2D object.

Greetings Jeff,

Thanks for your help! One last question if I may.

I am creating a jpeg from graphic converter which I know for a fact it is 32 bit deep. However no matter how I put it onto a Canvas or Backdrop the depth goes to zero. Even the simplest of code drops to 0.

me.Backdrop=XojoPic
var p As picture = XojoPic

Canvas1.Backdrop = p
Label1.text=p.Depth.ToText // =0

If all pics external or created by the program go to 0, then RGBSurface.pixel is useless.

Thanks!

Carl