The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Win32::Capture - Capture screen and manipulate it with Win32::GUI::DIBitmap instance.

SYNOPSIS

  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);
        }
  }

DESCRIPTION

The purposes of package are similar to Win32::Screenshot. But you can manipulate screen shot image with Win32::GUI::DIBitmap instance.

Screen capture functions

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.

CaptureRect($x, $y, $width, $height)

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.

CaptureScreen()

Capture whole screen include taskbar.

CaptureWindow($hWND, $dur, $flag)

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.
CaptureWindowRect($hWND, $dur, $x, $y, $width, $height)

Capture a portion of the window.

TIPS: Invoke FindWindowLike($text) helper function to find $hWND value.

Capturing helper function

FindWindowLike($text)
  @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.

SEE ALSO

Win32::Screenshot

Some documentation refer from here.

Win32::GUI::DIBitmap

The raw data from the screen will be loaded into Win32::GUI::DIBitmap instance.

See Win32::GUI::DIBitmap for more details.

MSDN

http://msdn.microsoft.com/library

AUTHOR

Lilo Huang

COPYRIGHT AND LICENSE

Copyright 2014 by Lilo Huang All Rights Reserved.

You can use this module under the same terms as Perl itself.