📌  相关文章
📜  PHP | imagickpixeliterator setIteratorFirstRow()函数

📅  最后修改于: 2022-05-13 01:56:19.796000             🧑  作者: Mango

PHP | imagickpixeliterator setIteratorFirstRow()函数

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

句法:

bool ImagickPixelIterator::setIteratorFirstRow( void )

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

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

下面的程序说明了PHP中的ImagickPixelIterator::setIteratorFirstRow()函数

方案一:

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

方案二:

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
)

参考: https://www. PHP.net/manual/en/imagickpixeliterator.setiteratorfirstrow。 PHP