Qt 替換圖片的顏色


QPixmap ChangeImageColor(QPixmap sourcePixmap, QColor origColor, QColor destColor)
{
    QImage image = sourcePixmap.toImage();
    for (int w = 0; w < image.width(); ++w)
        for (int h = 0; h < image.height(); ++h)
        {
            QRgb rgb = image.pixel(w, h);
            if (rgb == origColor.rgb())
            {
                ///替換顏色
                image.setPixel(w, h, destColor.rgba());
            }
        }
    return QPixmap::fromImage(image);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM