Qt:Qt5 Windows中BitBlt的替代品

Rob*_*nes 5 c++ qt porting bitblt qt5

我目前正在从Qt3到Qt5 移植一个开源解决方案(Albatross ATM解决方案http://www.albatross.aero/).信天翁是一个空中交通观众,需要非常好的表现.我可以管理各种问题,但不能显示部分.

显示架构依赖于一个bitblt命令,该命令首先将一个像素图复制到另一个像素图中,最后将像素图复制到屏幕上.

这是Qt3显示代码(工作和性能):

void CAsdView::paintEvent ( QPaintEvent * Event)
{
    QRect   rcBounds=Event->rect();

    QPainter tmp;

    for (int lay=0;lay<(int)m_RectTable.size();lay++) //For each drawing layer (there are 3) 
    {

        if (!m_RectTable[lay].isEmpty())
        {
            if (lay!=0)
                bitBlt(m_BitmapTable[lay],m_RectTable[lay].left(),m_RectTable[lay].top(),m_BitmapTable[lay-1],m_RectTable[lay].left(),m_RectTable[lay].top(),m_RectTable[lay].width(),m_RectTable[lay].height(),CopyROP); //m_BitmapTable is a QVector< QPixmap* >, m_RectTable is a QVector<QRect>

            tmp.begin(m_BitmapTable[lay]);

            if (lay==0)
                tmp.fillRect(m_RectTable[lay], *m_pBrush);

            OnDraw(&tmp,lay);
            tmp.end();
            m_RectTable[lay].setRect(0,0,-1,-1);
        }
    }
    bitBlt(this, rcBounds.left(), rcBounds.top(),m_BitmapTable[m_LayerNb-1],rcBounds.left(), rcBounds.top(),rcBounds.width(), rcBounds.height(), CopyROP);  
}
Run Code Online (Sandbox Code Playgroud)

我试过替换bitblt,drawPixmap但性能非常差,因为我必须经常显示屏幕.

这是新的Qt5代码:

void CAsdView::paintEvent ( QPaintEvent * Event)
{
    QRect   rcBounds=Event->rect();
    QPainter tmp;

    for (int lay=0;lay<(int)m_RectTable.size();lay++)
    {
        if (!m_RectTable.at(lay).isEmpty())
        {       
            tmp2.begin(m_BitmapTable[lay]);

            if (lay != 0)
            {
                tmp.drawPixmap(m_RectTable[lay].left(), m_RectTable[lay].top(), *m_BitmapTable.at(lay - 1), m_RectTable[lay].left(), m_RectTable[lay].top(), m_RectTable[lay].width(), m_RectTable[lay].height());//TOCHECK
                m_BitmapTable[lay] = m_BitmapTable[lay - 1].copy(m_RectTable[lay]);
            }

            if (lay==0)
                tmp.fillRect(m_RectTable.at(lay), *m_pBrush);

            OnDraw(&tmp, lay);
            tmp.end();
            m_RectTable[lay].setRect(0, 0, -1, -1);
        }
    }
    tmp.begin(this);
    tmp.drawPixmap(rcBounds.left(), rcBounds.top(), m_BitmapTable.at(m_LayerNb - 1), rcBounds.left(), rcBounds.top(), rcBounds.width(), rcBounds.height()); 
    tmp.end();
}
Run Code Online (Sandbox Code Playgroud)
  • 对于层,有3层.层0是最深的(背景),层2是最高的.使用此配置是为了确保空中交通始终显示在屏幕顶部.

  • OnDraw方法根据图层绘制自上一个paintEvent以来已更改的元素

问:你是否知道如何改进这种paintEvent方法以便恢复良好的行为并再次使用Qt5获得良好的表现?

Rob*_*nes 4

我在这里发现了问题。

在 Qt4/Qt5 中,drawPixmap/drawImage 显然是 bitblt 的最佳替代品。不幸的是,我对 QPixmap 的 scaled() 方法(在此处未显示的另一段代码中使用...)遇到了一些问题,这给我带来了不好的结果。我必须从 pixmap.resize() 转到 pixmap.scaled(),我在这里犯了一个错误。

我改变了它,现在我显然得到了很好的结果。因此,对于像我这样仍然想知道的人来说,Qt 中用于 Bitblt 的最佳替代方案是使用 QPainter 绘制 Pixmap。