Qt Gui 第五章绘图类

双缓冲

void Plotter::refreshPixmap()
{
    pixmap = QPixmap(size());
    pixmap.fill(this, 0, 0);

    QPainter painter(&pixmap);
    painter.initFrom(this);
    drawGrid(&painter);
    drawCurves(&painter);
    update();
}

QPixmap存储在graphics memory中,是针对屏幕进行特殊优化的,因此,它与实际的底层显示设备(操作系统提供的绘图引擎)息息相关。

当图片小的情况下,直接用QPixmap进行加载;当图片大的时候最好通过QImage进行加载,然后再用QPixmap用户绘制。例如:

QImage image;
image.load(":/pics/earth.png" );
QPainter painter(this);
QPixmap pixmapToShow = QPixmap::fromImage( image.scaled(size(), Qt::KeepAspectRatio) );
painter.drawPixmap(0,0, pixmapToShow);
 
// 附 QPixmap 和QImage 互相转换方法
QImage QPixmap::toImage() const;
static QPixmap QPixmap::fromImage(const QImage &image,,,);
// QPicture 不能从上述两类转换得来,只能从IO设备或者文件名路径加载。
bool load(QIODevice *dev, const char *format = Q_NULLPTR);
bool load(const QString &fileName, const char *format = Q_NULLPTR);

参考该csdn的博客:https://blog.csdn.net/qq_33266987/article/details/73187140

猜你喜欢

转载自www.cnblogs.com/czwlinux/p/12304095.html
今日推荐