Draw over a Photo on canvas

How i draw over a photo on canvas

Just draw on the canvas like you would normally…
Once the photo is on the canvas… you can do anything you want to it

g.drawpicture myphoto,0,0
g.forecolor=&cff0000 ' red
g.drawline 0,0,g.width,g.height

this put a photo on the canvas, and draws a diagonal red line across it

Thanks
But where i put that code on the canvas mousedown or ?

Everything has to origniate from the PAINT event

You cannot draw on a canvas outside of the PAINT event… the closest you can get it a Method where you pass the Graphic object, but that do has to be INSIDE the paint event

SUB PAINT(g as graphics)
     g.drawpicture myphoto,0,0
    g.forecolor=&cff0000 ' red
   g.drawline 0,0,g.width,g.height
END PAINT

OR (this method allows the same drawing code to be used by multiple canvas objects. I use this to print on screen, and on printer)

SUB PAINT(g as graphics)
   myPaint(g)
END PAINT

SUB myPaint(g as graphics)
g.drawpicture myphoto,0,0
g.forecolor=&cff0000 ' red
g.drawline 0,0,g.width,g.height
END myPaint

BUT NOT

SUB myPaint(g as graphics)
  canvas1.graphics.drawpicture myphoto,0,0
 canvas1.graphics..forecolor=&cff0000 ' red
 canvas1.graphics..drawline 0,0,g.width,g.height
END myPaint

this code do not trace the mouse point to draw and i need to trace the mouse move

No… this code is basic Canvas control.
If you want to write a drawing program, then you have some work to do
You need to monitor MOUSEDOWN, MOUSEUP, MOVEDRAG events
you need to keep track of where the mouse was when it went down, where it is during the drag
the delta that it moved, put code in the PAINT event do use those values to draw your lines, rectangles, circles or whatever
not to mention figuring out the appropriate times to invalidate your canvas in order to display a smooth “animation”

All of this is very doable, but beyond the scope of this forum to write or explain the total complexity of such an effort.

ok thanks

If any Class is ready to do this with the canvas

Alexis,

I’m not sure what you’re asking with “this”. You have to internalize how Xojo works:

You paint in the “Paint” event.
You control where the mouse is cliked and released in the “MouseDown” and “MouseUp” events.
You track the mouse in the “MouseMove” (for mouse movements) and “MouseDrag” (for mouse movements with the button pressed) event.

So you have several events that you need to coordinate.

A great set of examples on Canvas manipulation (not what you need specifically, but a lot of what you need to get there) can be seen in the AlwaysBusyCorner blog. They did a series on Canvas manipulation that is just fantastic:

http://alwaysbusycorner.wordpress.com/page/2/?s=canvas+realbasic

(page 2 of the series, showing the first entries. Page 1 contains the next ones)

You can also take a look at two of Joe Strout’s sample projects: http://www.strout.net/info/coding/rb/intro.html
(I have linked below to ZIP versions of the projects above updated to work in Xojo without modification)

DragPic: Dropbox - StroutNet-DragPics.zip - Simplify your life
MiniPaint: Dropbox - JoseStrout-MiniPaint.zip - Simplify your life
(MiniPaint relied on Resource Forks no longer supported, so when run the buttons don’t show the tools they should, I also haven’t checked if drawing is supposed to be interactive but right now it isn’t)

The samples are provided as-is, as they’re direct conversions of the old example on Joe’s site.

If you speak Spanish (I assume you do) you might want to ask around in the spanish forum as well. We’re few but for some things it may be easier to get you in the right direction.

Thanks
the mini paint this help me