hello there -
i’ve been searching for ways to rotate images by ‘arbitrary’ angles.
i’m basically trying to rotate an image based on a time thread - it
seems that Gdk::Pixbuf only allows for rotations of 90, 180, or 270
degrees - am i wrong? man i hope so… that would make things so very
much easier. i’ve played around with the Cairo context rotate method,
which accepts any angle, and provides a way to define the center of the
rotation - but i’ve had a million headaches trying to incorporate
cairo’s need to be painted when the window is realized into a
Gtk::Layout or Gnome::Canvas, with no luck.
assuming that in my hours of searching on google and here on the forum
i haven’t overlooked some obvious methods that would solve my problems,
i’ve been left trying various image libraries. i’ve tried RMagick which
has a handy rotate method, but is too slow to be used in the way i would
i stumbled upon Imlib2, which is quick and well documented and seems
like it should do everything i need - BUT…
win = Gtk::Window.new()
image = Imlib2::Image.load_image(“TradyBlix.png”)
gtkimg = Gtk::Image.new(“temp.png”)
…which ought to rotate my image by, well, 0 degrees -
rotates it instead to what seems like a random angle. if i run the
program several times in succession it rotates the image differently
any ideas what the heck is happening here? i’ve searched and
searched, and can’t seem to find any explanation.
any other ideas for ways to rotate an image in gtk would be
appreciated too. relying on the library to rotate and then save a temp
file to later load it under gtk seems barbaric, but i can’t figure out a
better way to do it.
thanks in advance -
Have you tried cairo already?
[email protected] wrote in post #980555:
Have you tried cairo already?
i have indeed, and it works nicely… i believe the problem i have
implementing cairo in what i want is that i don’t fully understand how
it works. i’ve got this:
file = “/home/jk/ruby/TradyBlix.png”
image = Gdk::Pixbuf.new(file, 100, 100)
win = Gtk::Window.new
draw_area = Gtk::DrawingArea.new
x = 10
@cc.rotate(x * Math::PI / 180)
@cc.set_source_pixbuf(image, 0, 0)
…and i’ve written something longer that ties it into a timer,
rotating the image 6 degrees per second. this works just fine, and
seems like the best solution. the problem i’m having is this: imagine
that you wanted to use one image as the second hand of a stopwatch,
rotating it on top of another image - this is similar to what i want to
do. what i have tried is placing the Gtk::DrawingArea defined above
along with another image into a Gtk::Layout, or a Gnome::Canvas.
neither of these work. it seems i lose the expose_event when i place
the DrawingArea into the Layout… is this true? i’ve tried figuring
out how to pass an expose signal through the layout to the drawing area,
but have had no luck.
do you know of a way to accomplish what i’m trying to do? i would
prefer to do it with cairo, and not rely on any other image library.
thanks for getting back to me…
Well, I am not so experienced in GTK widgets internals that I could
reply to your questions…
But I was able to do something working - it’s a volume peakmeter.
Usage is quite simple:
- it takes current volume level from GStreamer’s “volume” element
every 1/n second, but of course there could be any other source of the
- sets @peak and @rms variables to some negative values in the dB,
- call on the widget’s “update” method.
And it works well in many of my projects.
I don’t remember where I found the inspiration for that, I mean the
usage of expose signal and queue_draw(), but it works so I hadn’t
checked the internals… Like regular script kiddie, uh
Please see the attached file, maybe it will be helpful. Please ask in
case of any questions,
[email protected] wrote in post #980665:
…But I was able to do something working - it’s a volume peakmeter.
Usage is quite simple…
hi m -
thanks for getting back - going to have a good look at your script
when i get some free time… i was thinking of working on a peakmeter
myself, so i’m very interested to see what you’ve got there. sounds
like there could be some clues to solving my other problem too - thanks
- i’ll get back to you after looking at the script…
Of course, feel free to use it. Just please delete Radion module from
the module tree - it is reserved for my project’s name
2011/2/13 J. K. [email protected]:
hi marcin - jk here again…
thanks for the post - looks like it was just the #.queue_draw method
that i was looking for! rewrote something small using cairo that
rotates the images when a button is pushed - easy enough to tie into a
signal from the timer i’ve got.
the peakmeter looks great. if you don’t mind i’ll try to work it into
the audio player i’m writing (certainly give you credit when and if i
post the thing…)
thanks again -