Win32-Screenshot
view release on metacpan or search on metacpan
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Win32-Screenshot
version: 1.20
version_from: Screenshot.pm
installdirs: site
requires:
Image::Magick: 0
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.21
Makefile.PL view on Meta::CPAN
use 5.006;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Win32::Screenshot',
VERSION_FROM => 'Screenshot.pm',
PREREQ_PM => {
Image::Magick => 0,
},
($] >= 5.005 ?
(ABSTRACT_FROM => 'Screenshot.pm',
AUTHOR => 'P.Smejkal <petr.smejkal@seznam.cz>') : ()),
LIBS => ['comctl32.lib'],
DEFINE => '',
INC => '-I.',
);
if (eval {require ExtUtils::Constant; 1}) {
perl Makefile.PL
make
make test
make install
DEPENDENCIES
This module requires these other modules and libraries:
Image::Magick
SYNOPSIS
use Win32::Screenshot;
$image = CaptureRect( $x, $y, $width, $height );
$image->Write('screenshot.png');
DESCRIPTION
The package utilizes some Win32 API function and Image::Magick to let
you capture the screen, a window or a part of it. The "Capture*(...)"
functions returns a new Image::Magick object which you can easily use to
modify the screenshot or to store it in the file. You can define your
own post processing handlers and chain them in the list.
There are Perl equivalents of Win32 API functions for working with
windows implemented in the package. These functions will allow easy
identification of windows on the screen.
COPYRIGHT AND LICENCE
Copyright (C) 2004 by P.Smejkal
Screenshot.pm view on Meta::CPAN
{
no strict 'refs';
*$AUTOLOAD = sub { $val };
}
goto &$AUTOLOAD;
}
require XSLoader;
XSLoader::load('Win32::Screenshot', $VERSION);
use Image::Magick;
our @POST_PROCESS;
sub ppResize {
my $ratio = shift || 0.74;
my ($w, $h) = $_->Get('width', 'height');
$w = sprintf "%.0f", $w*$ratio;
$h = sprintf "%.0f", $h*$ratio;
$_->Resize(width=>$w,height=>$h,blur=>0.9,filter=>'Sinc');
}
Screenshot.pm view on Meta::CPAN
sub ppOuterGlow {
my ($outer, $inner, $width) = @_;
$inner ||= sprintf('#%02x%02x%02x', map {$_>>8} split (/,/, $_->Get('pixel[0,0]')));
$outer ||= 'white';
$width ||= 17;
my $top = sprintf "%.0f", $width/3.4;
# prepare background
my ($w, $h) = $_->Get('width', 'height');
my $g = Image::Magick->new;
$g->Set(size=>($w+$width).'x'.($h+$width));
$g->ReadImage('xc:'.$outer);
$g->Draw(
stroke=>$inner,
fill=>$inner,
primitive=>'rectangle',
points=> join(',',$top, $top, $w+$width-$top, $h+$width-$top),
);
$g->Blur(radius=>sprintf("%.0f", $width/2.8333), sigma=>3);
Screenshot.pm view on Meta::CPAN
$id = FindWindow(undef, $id);
}
return $id;
}
sub _capture {
CreateImage( CaptureHwndRect(@_) );
}
sub CreateImage {
my $image=Image::Magick->new();
$image->Set(magick=>'rgba');
$image->Set(size=>"$_[0]x$_[1]");
$image->Set(depth=>8);
$image->BlobToImage($_[2]);
return PostProcessImage($image);
}
sub PostProcessImage {
my $image = shift;
Screenshot.pm view on Meta::CPAN
=head1 SYNOPSIS
use Win32::Screenshot;
$image = CaptureRect( $x, $y, $width, $height );
$image->Write('screenshot.png');
=head1 DESCRIPTION
The package utilizes some Win32 API function and L<Image::Magick|Image::Magick>
to let you capture the screen, a window or a part of it. The
C<Capture*(...)> functions returns a new L<Image::Magick|Image::Magick> object which
you can easily use to modify the screenshot or to store it in the
file. You can define your own post processing handlers and chain them in
the list.
There are Perl equivalents of Win32 API functions for working with
windows implemented in the package. These functions will allow easy
identification of windows on the screen.
=head2 Image post-processing
The handler receives a reference to an Image::Magick object. If the
handler returns such reference it will be used instead of the input
one for further processing. It means that the handler can return
completely different image.
The handlers are organized in a list @POST_PROCESS. The item of the
list can be a string passed to C<eval> or a code reference. The image
will be passed to the handler as C<$_> for evals or C<$_[0]> for subs.
If you want to modify the list just use push or direct access.
Screenshot.pm view on Meta::CPAN
SW_SHOWMINIMIZED
SW_SHOWMINNOACTIVE
SW_SHOWNA
SW_SHOWNOACTIVATE
SW_SHOWNORMAL
=back
=head2 Screen capture functions
All these functions return a new L<Image::Magick|Image::Magick> object
on success or undef on failure. These function are exported by default.
=over 8
=item CaptureRect( $x, $y, $width, $height )
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.
Screenshot.pm view on Meta::CPAN
$screendata is a buffer filled with RGBA (4-bytes) data
representing the bitmap (Alpha is always 0xFF).
=item JoinRawData( $width1, $width2, $height, $raw1, $raw2 )
The function joins two bitmaps of the same height and return
the new bitmap data.
=item CreateImage( $width, $height, $rawdata )
Creates a new Image::Magick object from provided data and
calls all listed post-processing handlers. The function
returns the processed object.
=item PostProcessImage( $image )
Calls all listed post-processing handlers. The function
returns the processed object.
=back
=head2 Post-processing handlers
See L<Image::Magick> for other image processing functions. Typically
you can use methods like C<Label>, C<Quantize> and C<Set> to post-process
all captured images and then simply C<Write> the image to the file.
push @POST_PROCESS, sub {
$_[0]->Quantize( colors=>80, dither=>0 );
$_[0]->Set('quality', 100);
};
=over 8
Screenshot.pm view on Meta::CPAN
=back
=head1 SEE ALSO
=over 8
=item Win32::GUI
It was a good inspiration for me. I borrowed some code from the module.
=item Image::Magick
The raw data from the screen are loaded into Image::Magick object. You
have a lot of possibilities what to do with the captured image.
=item MSDN
http://msdn.microsoft.com/library
=item L<Win32::CaptureIE|Win32::CaptureIE>
Package that utilizes Win32::Screenshot to capture web pages or its
parts rendered by Internet Explorer.
Screenshot.xs view on Meta::CPAN
/* prepare directions for GetDIBits */
my_binfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
my_binfo.bmiHeader.biWidth = ww;
my_binfo.bmiHeader.biHeight = -hh; /* negative because we want top-down bitmap */
my_binfo.bmiHeader.biPlanes = 1;
my_binfo.bmiHeader.biBitCount = 32; /* we want RGBQUAD data */
my_binfo.bmiHeader.biCompression = BI_RGB;
if(GetDIBits(my_hdc, my_hbmp, 0, hh, buffer, &my_binfo, DIB_RGB_COLORS)) {
/* Convert RGBQUADs to format expected by Image::Magick .rgba file (BGRX -> RGBX) */
p = buffer;
for( i = 0 ; i < bufferlen/4 ; i++ ) {
*p = ((*p & 0x000000ff) << 16) | ((*p & 0x00ff0000) >> 16) | (*p & 0x0000ff00) | 0xff000000;
p++;
}
EXTEND(SP, 3);
PUSHs(sv_2mortal(newSViv(my_binfo.bmiHeader.biWidth)));
PUSHs(sv_2mortal(newSViv(abs(my_binfo.bmiHeader.biHeight))));
PUSHs(sv_2mortal(newSVpvn((char*) buffer, bufferlen)));
( run in 0.919 second using v1.01-cache-2.11-cpan-beeb90c9504 )