请问 Perl中使用Image:Magick模块,怎么获得像素的值


        请教 Perl中使用Image::Magick模块,如何获得像素的值?<br />

在PHP中,我可以这样获得像素值:

< php
$image = new Imagick("logo/1.jpg");
$r=$image->getImagePixelColor(0,0);
print_r($r->getColor());
exit();
>

//Array ( [r] => 47 [g] => 77 [b] => 17 [a] => 1 ) 



但在perl中,我这样得到的值是不一样的:

my $image = new Image::Magick;
$image->Read("logo/1.jpg");
my ($r, $g, $b) = $image->GetPixel(x=>0,y=>0,normalize=>0);
print $r;exit 0;

12079

正确的值应该是47



如果我使用Image::Imlib2,则结果是正确的:

my $image = Image::Imlib2->load("logo/1.jpg");
my ($r, $g, $b,$a) = $image->query_pixel(0,0);print $r;exit 0;

47


perl 程序开发 Perl语言基础

远野贵树_ 10 years, 6 months ago


突发奇想:

  Python code

  >>> 47.0/255 20: 0.1843137254901961 >>> 12079.0/65535 21: 0.1843137254901961 >>> pow(2,16) 22: 65536

yanda1 answered 10 years, 6 months ago


<fieldset> <legend> 探讨 </legend>
打印出来$r的值就是12079,错误的啊。不知道这个12079是否与47存在某种对应转换关系。图形图像方面了解实在太少。
</fieldset>


上帝总在微笑 answered 10 years, 6 months ago


看c pan 上的资料啊

路过的白菜 answered 10 years, 6 months ago


先打印出$image->GetPixel(x=>0,y=>0,normalize=>0)返回的值看看。

邪恶的路路花 answered 10 years, 6 months ago


RGB 值实际上就是r255^2+g255^1+b*255^0,也就是相当于255进制。

socat answered 10 years, 6 months ago

Your Answer