Draw in canvas with mouse and save picture in PNG

In MouseMove on a canvas I wrote this:

    dim g as Graphics = me.graphics
    g.ForeColor = ColorSelected
    g.FillOval X, Y, 3, 3

When I move the mouse over canvas I can draw something.
Now, for save the picture, I use this:

  Dim pic As New Picture(canv.Width, canv.Height, 32)
  
  canv.DrawInto(pic.Graphics, 0, 0)
  
  pic.Save(f, Picture.SaveAsPNG)

Where canv is canvas and f is a FolderItem.
But when I check the file is all blank.

don’t draw on the canvas and attempt to move to a picture… do it the other way around

draw on the picture, and simply display it on the canvas…

I suggest:

In Global:

Dim pic As New Picture(canv.Width, canv.Height, 32)

In the MouseMove: (It will draw dozens of times???)

Dim g as Graphics = pic.Graphics g.ForeColor = ColorSelected g.FillOval X, Y, 3, 3
In the Paint event of the Canvas

g.DrawPicture pic, 0, 0

and where you like

Dim f As FolderItem = ... (the file where you want to save) pic.Save f, Picture.SaveAsPNG

In the MouseMove: (It will draw dozens of times???)

Dim g as Graphics = pic.Graphics
g.ForeColor = ColorSelected
g.FillOval X, Y, 3, 3

2 things:
MouseMove fires even if the mouse button is not pressed… is that what you expected?

Also, to avoid unnecessary drawing

[code]static oldx as integer
static oldy as integer
static g as Graphics
if g is null then g = pic.Graphics

g.ForeColor = ColorSelected
if x <> oldx or y <> oldy then
g.FillOval X, Y, 3, 3
oldx = x
oldy = y //wont draw again until the mouse has actually moved
end if[/code]