Win32::Capture - Capture screen and manipulate it with Win32::GUI::DIBitmap instance.
use Win32::Capture; $image = CaptureScreen(); # Capture whole screen. $image->SaveToFile('screenshot.png'); # or $image = CaptureRect($x, $y, $width, $height); # Capture a portion of window. $image->SaveToFile('screenshot.png'); # or @hwnds = FindWindowLike('CPAN'); # Invoke helper function to get HWND array. if ($#hwnds<0) { print "Not found"; } else { foreach (@hwnds) { my $image = CaptureWindowRect($_, 2, 0, 0, 400, 300); $image->SaveToFile("$_.jpg", JPEG_QUALITYSUPERB); } }
The purposes of package are similar to Win32::Screenshot. But you can manipulate screen shot image with Win32::GUI::DIBitmap instance.
All of these functions are returning a new Win32::GUI::DIBitmap instance on success or undef (a.k.a undefined variables) on failure. All functions are exported by default.
Capture a portion of the screen. The [0, 0] coordinate is on the upper-left corner of the screen. The [$x, $y] defines the the upper-left corner of the rectangle to be captured.
Capture whole screen include taskbar.
Capture whole window include title bar and window border, or client window region only.
Set $dur to wait for a while before capturing.
TIPS: Invoke FindWindowLike($text) helper function to find $hWND value.
$flag = 0 : Entire window will be captured (with border) $flag = 1 : Only client window region will be captured.
Capture a portion of the window.
@hwnds = FindWindowLike('CPAN'); if ($#hwnds<0) { print "Not found"; } else { foreach (@hwnds) { my $image = CaptureWindowRect($_, 2, 0, 0, 400, 300); $image->SaveToFile("$_.jpg", JPEG_QUALITYSUPERB); } }
The $text argument stands for a part of window title. FindWindowLike will return an array holds HWND elements.
Some documentation refer from here.
The raw data from the screen will be loaded into Win32::GUI::DIBitmap instance.
See Win32::GUI::DIBitmap for more details.
http://msdn.microsoft.com/library
Lilo Huang
Copyright 2014 by Lilo Huang All Rights Reserved.
You can use this module under the same terms as Perl itself.
To install Win32::Capture, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::Capture
CPAN shell
perl -MCPAN -e shell install Win32::Capture
For more information on module installation, please visit the detailed CPAN module installation guide.