Pict1 = Pict2 Relationship ?

Somewhere in a project I have a bug. I resolved it when I reload a Picture from file.

An hour later I fall into another bug and I found it, but I am unsure why.

In the code below, what happens to Pict1 ?

[code]Pict2 = Pict1 // Initialized at the same size above

Pict2.Graphics.DrawString “Emile”,10,20[/code]

The REAL question is: WIll the “Emile” String appear too in Pict1 ?

Hi Emile,

A Object is Always referenced.

So keep in mind a picture is put in memoryspace and Pict1 is only a Ref to it (Link / shortcut) .
Pict2 = Pict1 means that also Pict2 now having the same reference to this picture…
So when you change the picture it’s seen by Pict1 and Pict2
Remark : Integers, and Strings doesn’t have this way of working.

Look at Picture.GetData to see how you can copy pictures.

Thanks Erwin for your reply.

So, in my code above, Pict2 is a simple “Alias” of Pict 1… (holds a reference to Pict1: everything I do to Pict2 is in fact done in Pict1…)

This explain my bug, a bug I do not found any explanation previously.

To be clear, think at Pict1 as a Template Pict and Pict2 is a place where I add other graphics to the Template.

I will now use:

Pict2.DrawPicture Pict1,0,0

Unfortunately, it is not possible to lock a Picture.

My trouble (error above) certainly comes from:

Canvas1.Backdrop = Pict1


Pict1 = Canvas1.Backdrop

BTW: I do understand why there is no collateral error in these two above lines.

For your template picture and additional (overlay) graphics (I asume)

It’s better to play with the paint event of the Canvas object

My approach would be:

Create a new class (IDE Insert new class)
Set in Inspector supet to Canvas (superclass this Canvas object) .

add property for you template picture example : Pict_Template
add property for your adjustments perhaps a group2d object : pict_Overlay2D

Now Add event handler to your class
use g.drawpicture(Pict_Template,X,Y etc etc) (check help)

create methods in this object for drawing thing on your picture (Text, Ovals, Rect etc etc)

use g.drawobject(pict_Overlay2D)
See manual for examples of group2d

Place your new class on window and place a button to forced refresh of canvas (to play)
Paint event is called when user drags window / resize etc etc. .

If you want to do more funky stuff with your picture …(blending, collorchange etc)
Learn to copy your picture data into a memoryblock and recreate picture again and again .

I hope I give you a direction where to look for…

Kind regards,

Thank you Erwin.