Color of a screen pixel: Difference between revisions
Content deleted Content added
SqrtNegInf (talk | contribs) Added Perl example |
SqrtNegInf (talk | contribs) Added Perl 6 example |
||
Line 710:
print "RGB: $red, $green, $blue\n";
unlink $file;</lang>
{{out}}
<pre>RGB: 20, 2, 124</pre>
=={{header|Perl 6}}==
This example works with MacOS, customize with the appropriate <tt>screencapture</tt> utility for other OSes.
<lang perl6>use GD::Raw;
my $file = '/tmp/one-pixel-screen-capture.png';
qqx/screencapture -R 123,456,1,1 $file/;
my $fh = fopen($file, "rb") or die;
my $image = gdImageCreateFromPng($fh);
my $pixel = gdImageGetPixel($img, 0, 0);
my ($red,$green,$blue) =
gdImageRed( $image, $pixel),
gdImageGreen($image, $pixel),
gdImageBlue( $image, $pixel);
say "RGB: $red, $green, $blue";
fclose($fh);
unlink $file;</lang>
{{out}}
|