Win32::Capture - Capature Win32 screen with lightweight Win32::GUI::DIBitmap.
use Win32::Capture; $image = CaptureScreen(); # Capture Whole screen. $image->SaveToFile('screenshot.png'); #or $image = CaptureRect( $x, $y, $width, $height ); # Capture a part of window. $image->SaveToFile('screenshot.png'); #or @WIN = FindWindowLike('CPAN'); # Find the HWND to be captured. if($#WIN<0) { print "Not found"; }else{ foreach(@WIN) { my $image = CaptureWindowRect($_,2,0,0,400,300); $image->SaveToFile("$_.jpg",JPEG_QUALITYSUPERB); } }
The package is similar to Win32::Screenshot, also using Win32 API function, but with Image Process in Win32::GUI::DIBitmap to let you capture the screen, a window or a part of it. The Capture*(...) functions returns a new Win32::GUI::DIBitmap object which you can easily use to modify the screenshot or to store it in the file.
Capture*(...)
All these functions return a new Win32::GUI::DIBitmap object on success or undef on failure. These function are exported by default.
Captures part of the screen. The [0, 0] coordinate is the upper-left corner of the screen. The [$x, $y] defines the the upper-left corner of the rectangle to be captured.
Captures whole screen including the taskbar.
Captures whole window including title and border or only for Client Window. The second parameter is how many time wait for the Window be Changed to Top.
TIPS: You can using FindWindowLike to find the HWND.
flag = 0 : All the window is capture (with border) flag = 1 : Only the Client window is capture
Captures a part of the window. Pass the window handle with the function parameter. The second parameter is how many time wait for the Window be Changed to Top.
TIPS: You can using FindWindowLike to find the HWND element(s).
Functions for find the Window HWND to capture.
@WIN = FindWindowLike('CPAN'); if($#WIN<0) { print "Not found"; }else{ foreach(@WIN) { my $image = CaptureWindowRect($_,2,0,0,400,300); $image->SaveToFile("$_.jpg",JPEG_QUALITYSUPERB); } }
The parameter is a part of window title, and FindWindowLike will Return an Array including HWND.
Some documentation refer from here.
The raw data from the screen are loaded into Win32::GUI::DIBitmap object. You have a lot of possibilities what to do with the captured image.
http://msdn.microsoft.com/library
Lilo Huang
Copyright 2006 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.