Re: Working with images




On Aug 18, 2004, at 9:49 PM, Daniel Kasak wrote:

I want to do some simple image manipulation. I haven't done this at all before, so I'm a little lost as to where to start.

I'd like to make a splash screen that has a background image and another image which fades in and then fades back out.

then Gtk2/gtk-demo/pixbufs.pl really is for you. you'll need a pixbuf to use as the offscreen image, your two source images, and a recurring timeout to "animate" the fade. the fade will consist of calling Gtk2::Gdk::Pixbuf::composite() with different alpha values, where alpha will be a function of time (since you probably want a slow fade).


I've had a look at the pixmap example in the gtk-demos folder, and that just makes me more confused. The end result is impressive, but as to how it works ... well ... no idea.

the timeout() sub is where the magic happens. it fills the pixbuf with the background image, then loops through the smaller images and computes a new location based on the frame number and radius (this is how they spin and scale). all of the real drawing happens in the composite() method, which is what handles compositing the small image pixbuf ($images[$i]) into the main image pixbuf ($frame). "compositing" is like copying, but you use an alpha value to determine how much opacity the new pixel values get.

the other stuff in that "example", mostly to do with rectangle intersections and such, will not be of interest to you unless you're planning to make one image move around.


Does anyone have some links to docs / examples for people who don't know what the various Gtk2::Gdk objects / methods actually do?

the C API reference docs for these functions are your best bet:

gdk_pixbuf_composite() (a.k.a. Gtk2::Gdk::Pixbuf::composite()) is on this page: http://developer.gnome.org/doc/API/2.0/gdk-pixbuf/gdk-pixbuf- scaling.html
and its description even includes a diagram!  :-)

gdk_pixbuf_render_to_drawable() (a.k.a. Gtk2::Gdk::Pixbuf::render_to_drawable()) is actually in Gdk itself, since it deals with window objects:
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Pixbufs.html
NOTE: since gtk+ 2.2, you should use gdk_draw_pixbuf() (Gtk2::Gdk::Drawable::draw_pixbuf()) instead of gdk_pixbuf_render_to_drawable().

--
"Quit hittin' yourself!  Quit hittin' yourself!"
   -- Elysse, playing with a newborn baby.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]