[Pdx-pm] Scan OSX Window pixel by pixel

Joshua Keroes joshua at keroes.com
Tue Mar 29 23:40:30 PDT 2011


On Tue, Mar 29, 2011 at 11:21 PM, Eric Wilhelm <enobacon at gmail.com> wrote:
> # from Joshua Keroes
> # on Tuesday 29 March 2011 23:00:
>
>>my $image = Imager::Search::Screenshot->new(
>>    [ id => 0 ],
>>    driver => 'BMP24',
>>);
>>
>>Granted, that's a large region, but for my needs, 12 seconds is way
>> too slow.
>
> I think there is something being pre-computed in the Imager::Search
> constructor.  Try it with just Imager::Screenshot.
>
>  $ time perl -MImager::Screenshot=screenshot -e 'my $s = screenshot();'
>  real    0m1.131s
>
> Then I think you just want my $color = $s->getpixel(x => 10, y => 20).
> There is also a syntax for getting multiple pixels at once.

timethis( 100, sub { screenshot()->getpixel(x => $_, y => $_) } );

timethis 100:  5 wallclock secs ( 2.54 usr +  1.92 sys =  4.46 CPU) @
22.42/s (n=100)

.0446 sec to run screenshot() and getpixel() - I can work with that!

You win thirty-three and a third rockstar points,
Joshua


More information about the Pdx-pm-list mailing list