Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Here is an updated version that will cycle thru any legal graphic file in the pwd, fading from one image to the next, slideshow fashion. It will read each file on every cycle thru the list, so you may want to store the pixbufs in a hash so they only are read once.
#!/usr/bin/perl use strict; use warnings; use Gtk2 '-init'; # a list to get most of the standard graphic formats into a glob my @exts = qw(wbmp wmf jpeg jpg bmp gif pcx png pnm pbm pgm ppm tga targa xbm tiff tif xpm ); @exts = map { $_ = "*.$_" } @exts; #map to setup the glob below my @files = <@exts>; #non recursive if(scalar @files == 0){ die "No photo files found\n" } print "@files\n"; my $mw = Gtk2::Window->new; $mw->signal_connect('destroy', sub { Gtk2->main_quit }); my $vp = Gtk2::Viewport->new(undef, undef); $mw->add($vp); # start with base image my $alpha = 0; my $next = 0; my $pb_base = Gtk2::Gdk::Pixbuf->new_from_file_at_scale ($files[0], 60 +0,600,0); my $pb_base_orig = $pb_base->copy(); #get next pixbuf push (@files,shift(@files)); my $pb_next = Gtk2::Gdk::Pixbuf->new_from_file_at_scale ($files[0], 60 +0,600,0); my $image = Gtk2::Image->new_from_pixbuf ($pb_base); $vp->add($image); $mw->set_title("fade demo"); $mw->show_all(); my $id = Glib::Timeout->add (100, \&sequence); Gtk2->main; sub sequence{ if( $next ){ # set base to be the previous next $pb_base = $pb_next; $pb_base_orig = $pb_base->copy(); $image->set_from_pixbuf ($pb_base); Gtk2->main_iteration while Gtk2->events_pending; #get next pixbuf push (@files,shift(@files)); $pb_next = Gtk2::Gdk::Pixbuf->new_from_file_at_scale ($files[0], + 600,600,0); $next = 0; $alpha = 0; }else{ $alpha += 5; print "$alpha\n"; if ($alpha == 255){ $next = 1; } #$pixbuf1->composite ($pixbuf, $dest_x, $dest_y, $dest_width, $dest +_height, # $offset_x, $offset_y, $scale_x, $scale_y, $interp_type, $o +verall_alpha) $pb_next->composite ($pb_base, 0, 0, 600, 600, 0, 0, 1, 1, 'nearest', $alpha); # 0 <= alpha <= 255 $image->set_from_pixbuf ($pb_base); } Gtk2->main_iteration while Gtk2->events_pending; # prevents accumulation of pixbuf changes $pb_base = $pb_base_orig->copy(); return 1; }

I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re: Gtk2 Simple Image Fade by zentara
in thread Gtk2 Simple Image Fade by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-24 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found