假设我想拍摄一张图片,请将其所有像素向右移一个像素,然后保存一个像素。我想这样的代码:使用Perl修改图像中的像素
my $image_file = "a.jpg";
my $im = GD::Image->newFromJpeg($image_file);
my ($width, $height) = $im->getBounds();
my $outim = new GD::Image($width, $height);
foreach my $x (1..$width)
{
foreach my $y (1..$height)
{
my $index = $im->getPixel($x-1,$y-1);
my ($r,$g,$b) = $im->rgb($index);
my $color = $outim->colorAllocate($r,$g,$b);
$outim->setPixel($x,$y,$color);
}
}
%printing the picture...
这并不做的伎俩;它以一种颜色绘制除x = 0或y = 0之外的所有像素。我哪里错了?
感谢您的回答,很显然,我没有得到任何地方,其中x = 0或y = 0,但为什么其余的是一种颜色,而第一张图片是彩色的? – ronash 2012-03-08 19:29:43
您是否尝试过“打印”原始图像,以确保它被正确读取? – 2012-03-08 19:36:47
是的,它确实打印完全相同的图像。 – ronash 2012-03-08 19:38:27