Copy a Canvas

I like to copy the drtawing of Canvas1 into Canvas 2
But the only result is, a line and a arc in Canvas1 and a withe area in Canvas2.
What is wrong?

[code]Dim DBase As New SQLiteDatabase
Dim MyRec As RecordSet
Dim rec As New DatabaseRecord
Dim pic As New Picture(Canvas1.Width, Canvas1.Height, 32)

Canvas1.Graphics.DrawLine(100,100,600,100)
Canvas1.Graphics.DrawOval(100,100,50,50)
Canvas1.DrawInto(pic.Graphics, 0,0)

DBase= New SQLiteDatabase
If DBase.Connect() Then
DBase.SQLExecute(“CREATE TABLE Drawing(ID INTEGER, Pic BLOB)”)
DBase.Commit
rec.IntegerColumn(“ID”)=1
rec.PictureColumn(“pic”) = pic
DBase.InsertRecord(“Drawing”, rec)
MyRec = DBase.SQLSelect(“SELECT * FROM Drawing WHERE ID=1”)
ID.Text = MyRec.Field(“id”)
Canvas2.Backdrop= MyRec.Field(“Pic”)
End If
DBase.Close[/code]

You draw in the volatile part of the Canvas at first, then use the Canvas Backdrop.

Either draw in a Picture instance and set it to the canvas’ Backdrop OR draw to canvas Backdrop and make the copy from there.

In short, draw everything in the Canvas.Backdrop picture and make the copy from there.

[quote=226044:@Hans Riemers] Canvas1.Graphics.DrawLine(100,100,600,100)
Canvas1.Graphics.DrawOval(100,100,50,50)
Canvas1.DrawInto(pic.Graphics, 0,0)[/quote]

Drawing to Canvas.Graphics has been deprecated and is strongly discouraged. As a matter of fact, the Graphics property is not even part of the LR about Canvas at http://documentation.xojo.com/index.php/canvas ; it is recommended to use the Paint event instead.

That said, you can very well create a picture for the backdrop and use Canvas1.Backdrop.Graphics.

  • Add pic and pic2 as picture as properties of the window
  • In Canvas 1 :

Sub Open() #If TargetWin32 then App.UseGDIPlus = True #Endif pic = new picture(me.width,me.height) me.backdrop = pic Canvas1.Backdrop.Graphics.DrawLine(100,100,600,100) Canvas1.Backdrop.Graphics.DrawOval(100,100,50,50) End Sub
I used the explicit name Canvas1 for demonstration, but it would be better to use me.Backdrop.Graphics

  • In Canvas2 :

Sub Open() #If TargetWin32 then App.UseGDIPlus = True #Endif pic2 = new picture(me.width,me.height) me.backdrop = pic2 End Sub

  • In a button :

Sub Action() Canvas1.DrawInto(Canvas2.Backdrop.Graphics, 0,0) Canvas2.Invalidate End Sub

Canvas2.Invalidate is necessary to update its display.

Problem: i can’t draw in the Canvas, this was only a proposal, i draw from different methods in to the canvas.

What I posted is easy to change to draw from anywhere. You can dump the drawing into the button if you want, for instance.

It should not be a problem, it should be an occasion to learn …

OK, thanks

Last question, how can i empty the Canvas, refresh don’t work.

Call Refresh(), but do nothing in the Paint event.

Refresh doesnt works, and Refresh() is not a option, maby the properties Pia and Pic 2 shoud be clean?? but how?

Call Refresh(), but do nothing in the Paint event.

pic = new picture(Canvas1.Width, Canvas1.Height)

He wants to draw from outside I showed him how to use the Backdrop picture Graphics.

I have try every think.
I have make a button with:

Sub Action Button Clear pic = new picture(Canvas1.Width, Canvas1.Height) Canvas1.Refresh Canvas1.Invalidate Canvas1.EraseBackground=False Canvas2.Refresh End Sub
But the results are nothing: the drawing is still in the cacans or in the Pic???

[quote=226156:@Hans Riemers]I have try every think.
I have make a button with:

Sub Action Button Clear pic = new picture(Canvas1.Width, Canvas1.Height) Canvas1.Refresh Canvas1.Invalidate Canvas1.EraseBackground=False Canvas2.Refresh End Sub
But the results are nothing: the drawing is still in the cacans or in the Pic???[/quote]

What on earth are you trying to accomplish ? ? ?

Sub Action Button Clear pic = new picture(Canvas1.Width, Canvas1.Height) Canvas1.DrawInto(pic.Graphics, 0,0) End Sub

As Michel instructed, do all your drawing into a Picture which is a property of the window. In Canvas1.Paint and Canvas2.Paint, simply use DrawPicture to show the drawing in the canvas. To clear the canvas(es), create a blank picture and refresh/invalidate the canvas.