代码 :
QPainter p(this);
QPixmap map(width, height);
map.fill(Qt::transparent);
p.begin(&map);
//p.setTransform(ma);
p.drawRect(QRect(0, 0, 100, 100)); //绘制
p.end();
map.save("C:/Users/Administrator/Desktop/123.png", "PNG"); //保存
步骤:
1.实例化QPainter 和 QPixmap;
2.在把painter 设置绘制在 pixmap 上(用begin()函数);
3.然后绘制更新painter ;
4.绘制结束(end()),保存pixmap图像;
抗锯齿,反走样:
p.setRenderHint(QPainter::Antialiasing, true);这句写在draw之前,begin之后。