php firstrow,PHP ImagickPixelIterator setIteratorFirstRow()用法及代码示例

ImagickPixelIterator::setIteratorFirstRow()函数是PHP中的内置函数,用于将像素迭代器设置为第一像素行。

用法:

bool ImagickPixelIterator::setIteratorFirstRow( void )

参数:此函数不接受任何参数。

返回值:成功时此函数返回TRUE。

以下示例程序旨在说明PHP中的ImagickPixelIterator::setIteratorFirstRow()函数:

程序1:

// Create a new imagick object

$imagick = new Imagick(

'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');

// Get the pixel iterator

$pixelIterator = $imagick->getPixelIterator();

// Set the pixel iterator to 50

$pixelIterator->setIteratorRow(50);

// Get the current iterator row

echo "Current row is " . $pixelIterator->getIteratorRow();

// Set the iterator to first row

$pixelIterator->setIteratorFirstRow();

// Get the current iterator row

echo "
Current row is " . $pixelIterator->getIteratorRow();

?>

输出:

Current row is 50

Current row is 0

程序2:

// Create a new imagick object

$imagick = new Imagick(

'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');

// Get the pixel iterator

$pixelIterator = $imagick->getPixelIterator();

$pixelIterator->setIteratorRow(40);

// Get the current iterator row

$row = $pixelIterator->getCurrentIteratorRow();

echo "Colors of 61th and 62nd pixel from 40th row are:
";

print("Pixel 60:" . "

".print_r($row[60]->getColor(), true)."
");

print("Pixel 61:" . "

".print_r($row[61]->getColor(), true)."
");

// Set the iterator to first row

$pixelIterator->setIteratorFirstRow();

// Get the current iterator row

$row = $pixelIterator->getCurrentIteratorRow();

echo "First two colors of pixels from first row are:
";

print("Pixel 1:" . "

".print_r($row[0]->getColor(), true)."
");

print("Pixel 2:" . "

".print_r($row[1]->getColor(), true)."
");

?>

输出:

Colors of 61th and 62nd pixel from 40th row are:

Pixel 60:

Array

(

[r] => 110

[g] => 199

[b] => 131

[a] => 1

)

Pixel 61:

Array

(

[r] => 23

[g] => 165

[b] => 57

[a] => 1

)

First two colors of pixels from first row are:

Pixel 1:

Array

(

[r] => 255

[g] => 255

[b] => 255

[a] => 1

)

Pixel 2:

Array

(

[r] => 255

[g] => 255

[b] => 255

[a] => 1

)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值