Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

screenshot module on Windows

by spx2 (Deacon)
on Feb 10, 2010 at 17:22 UTC ( [id://822469]=perlquestion: print w/replies, xml ) Need Help??

spx2 has asked for the wisdom of the Perl Monks concerning the following question:

Win32::Screenshot doesn't build because Image::Magick doesn't build. I also tried Win32::Capture which doesn't build. This is all on Strawberry Perl on Windows. Any ideas on any working module that does this under Windows ? Thanks

Replies are listed 'Best First'.
Re: screenshot module on Windows
by zentara (Cardinal) on Feb 10, 2010 at 17:59 UTC
    You can install Gtk2 on win32 fairly easily with Camelbox: A build of Gtk2-Perl for Windows. Then you can do this.
    #!/usr/bin/perl use warnings; use strict; use Gtk2 -init; use Time::HiRes qw( time ); my $time_start = time; my $s = Gtk2::Gdk::Screen->get_default; my $w = $s->get_root_window; # pixbuf = $pixbuf->get_from_drawable ($src, $cmap, $src_x, $src_y, # $dest_x, $dest_y, $width, $height +) while (1){ my $p = Gtk2::Gdk::Pixbuf->get_from_drawable ( $w, undef, 0, 0, 0, 0, $s->get_width, $s->get_height); $p->save (time.'.png', "png"); } my $time_end = time; my $diff = $time_end - $time_start; print "$diff\n";

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
Re: screenshot module on Windows
by BrowserUk (Patriarch) on Feb 10, 2010 at 19:22 UTC

    If you have a command line bmp to png converter (or jpg etc. like this one), then you can do this quite easily without any of the complex installs:

    #! perl -slw use strict; use Win32::GuiTest qw[FindWindowLike SetForegroundWindow SendKeys]; use Win32::Clipboard; my $clip = Win32::Clipboard->new(); my @windows = FindWindowLike( 0, $ARGV[ 0 ] ); #Find it die "Couldn't find window '$ARGV[ 0 ]" unless @windows; for (@windows) { SetForegroundWindow( $_ ); # Make it active sleep 1; ## Send the Alt-print screen key sequence to copy ## the active window to the clipboard SendKeys("%{PRTSCR}"); } my $fname = "$ARGV[ 0 ]-@{[ time() ]}"; print $fname; if( my $bitmap = $clip->GetBitmap() ) { local $\; my $bmpfile = $fname . '.bmp'; open my $bmp, '>', $bmpfile or die $!; binmode $bmp; print $bmp $bitmap; close $bmp; print "Bitmap written to $bmpfile\n"; system "bmp2png $bmpfile"; print "Converted to $fname.png"; } else { die "Couldn't get bitmap from clipboard"; } __END__ C:\test>screengrab Opera Opera-1265829469 Bitmap written to Opera-1265829469.bmp OK Opera-12658294 ooooooooooooooooooooooooooooooooooooooooooooooo +ooooo Converted to Opera-1265829469.png

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: screenshot module on Windows
by jmcnamara (Monsignor) on Feb 10, 2010 at 19:41 UTC

    It would be best to use one of the dedicated modules but in the absence of those the following simple utility might do what you need: Screen capture on Windows.

    See the full example at the linked node but here is the shorter version.

    #!/usr/bin/perl -w use strict; use Win32::Clipboard; use Win32::GuiTest 'SendKeys'; # Send "Print Screen" key to Windows. SendKeys('{PRTSCR}'); # Get the image from the clipboard. my $screen = Win32::Clipboard::GetBitmap() or die "No image captured: $!\n"; # Print the image to a file. open BITMAP, "> screen.bmp" or die "Couldn't open bitmap file: +$!\n"; binmode BITMAP; print BITMAP $screen; close BITMAP; __END__

    --
    John.

Re: screenshot module on Windows
by tonyc (Friar) on Feb 10, 2010 at 22:06 UTC
    Could I please see the failed build log for Imager::Screenshot? I just built it successfully with the latest Strawberry Perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://822469]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2025-06-23 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.