查詢

ImagickPixelIterator::getCurrentIteratorRow()函式—用法及示例

「 獲取當前畫素迭代器的行數 」


函式:ImagickPixelIterator::getCurrentIteratorRow()

適用版本:Imagick 3.1.0以上

用法:getCurrentIteratorRow() 方法用於獲取當前畫素迭代器的行數。

示例:

// 建立一個新的Imagick物件並讀取影象檔案
$image = new Imagick('image.jpg');

// 建立畫素迭代器
$iterator = $image->getPixelIterator();

// 遍歷畫素迭代器的每一行
foreach ($iterator as $row => $pixels) {
    // 獲取當前行的行數
    $currentRow = $iterator->getCurrentIteratorRow();
    
    // 輸出當前行數
    echo "當前行數:$currentRow\n";

    // 遍歷當前行的每個畫素
    foreach ($pixels as $column => $pixel) {
        // 處理每個畫素
    }
}

在上面的示例中,我們首先建立了一個Imagick物件並讀取了一個影象檔案。然後,我們使用getPixelIterator()方法建立了一個畫素迭代器。接下來,我們使用foreach迴圈遍歷畫素迭代器的每一行。在迴圈內部,我們透過呼叫getCurrentIteratorRow()方法獲取當前行的行數,並將其輸出。然後,我們可以在迴圈內部進一步處理每個畫素。

補充糾錯
熱門PHP函式
分享連結