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);
}
原文地址:https://www.cnblogs.com/qq702368956/p/13374467.html