先上干货。
Qt下修改图片背景色的方法:
方法一:
QPixmap CKnitWidget::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);
}QPixmap CKnitWi