0

I would like to draw a simple (red) line over an image with gtkmm (in c++).

I have the image : Gtk::Image *image which is displayed in my window.

But I would like the line to change of position (I mean : draw another line) when a function is called. I need your help because I didn't find how to draw over an existing image...

Thank you for your help !

EDIT : A solution for me would be to overlay the image by an image with alpha channel... but I don't know how to to that :-/

Jav
  • 1,445
  • 1
  • 18
  • 47

2 Answers2

1

You should not actually draw in the image, instead you draw in the window.

First put the image in the window (blitting or some other means) then draw the line.

See e.g. this link on how to draw straight lines.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • I don't know how to "blit" with gtk ... Sorry but it is the first time I use gtk and I am a little bit lost. – Jav Feb 11 '13 at 10:13
1

Connect to the "expose-event" (GTK2) or "draw" (GTK3) signal of the GtkImage. I think you should use the C++ equivalent of g_signal_connect_after (which in in GObject), and not the g_signal_connect one, so you get a chance of drawing after the image has been drawn, so your drawing is on top of it. To draw you need to use cairomm, and Joachim already gave you a link to a cairomm tutorial.

liberforce
  • 11,189
  • 37
  • 48
  • I almost have a working example of this answer, except that mine is written in Python. Shouldn't this answer be accepted? – LRMAAX Sep 28 '13 at 22:11