// 透明色为品红qRgba(255,0,255,255)
将非品红色转换成black,品红色转换成white,以做mask图用
QPixmap Form::convertToBW(const QImage &map)
{
QImage img(map);
for (int i = 0; i < img.height(); i++)
{
for (int j = 0; j < img.width(); j++)
{
if(img.pixel(j, i) == qRgba(255,0,255,255))
img.setPixel(j, i, qRgba(255,255,255,255));//Or you can use qRgba(0,0,0,0) instead for trans
else
img.setPixel(j, i, qRgba(0,0,0,255));//Or you can use qRgba(0,0,0,0) instead for trans
}
}
return QPixmap::fromImage(img, Qt::MonoOnly);
};
QPixmap Form::convertToBW(const QString &file)
{
QImage img;
img.load(file);
return convertToBW(img);
}
调用方法:
QPixmap piximg = convertToBW("bg.png");
piximg.save("kk05.png");
阅读(4681) | 评论(0) | 转发(0) |