I have the following code:
use Imager::Screenshot 'screenshot';
my $img = screenshot(hwnd => 'active',
left => 450,
right => 200,
top => 50,
bottom => 50
);
$img->write(file => 'screenshot.png', type => 'png' ) ||
print "Failed: ", $img->{ERRSTR} , "\n";
it prints:
“Can’t call method “write” on undefined value at line 3″
but when I do:
use Imager::Screenshot 'screenshot';
my $img = screenshot(hwnd => 'active',
left => 100,
right => 300,
top => 100,
bottom => 300
);
$img->write(file => 'screenshot.png', type => 'png' ) ||
print "Failed: ", $img->{ERRSTR} , "\n";
It does take a screenshot. Why would the left, right, top and bottom values matter here?
EDIT:
After some research I found out that left param must be smaller than right param and top must be smaller than bottom.
Have you tried checking the error? e.g.
my $img = screenshot(...) or die Imager->errstr;edit: try this code: