QT 實現圖片旋轉的兩種方法


第一種方案

使用 QPixmap 的 transformed 函數來實現旋轉,這個函數默認是以圖片中心為旋轉點,不能設置旋轉的中心點,使用如下:

QMatrix matrix;
matrix.rotate(45);

QLabel *Label= new QLabel();
Label->setPixmap(QPixmap(“:/images.png”).transformed(matrix, Qt::SmoothTransformation));

該段程序實現的效果是使圖片順時針旋轉 45 度。

第二種方案

使用 QPainter 這位“畫家”,示例程序如下:

void Widget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap disc(":/disc.png");

    /* 碟機轉動 */
    if(imageRotate++ == 360)
        imageRotate = 0;
    /* 設定旋轉中心點 */
    painter.translate(130,150);
    /* 旋轉的角度 */
    painter.rotate(imageRotate);
    /* 恢復中心點 */
    painter.translate(-130,-150);
    /* 畫圖操作 */
    painter.drawPixmap(40,60,180,180, disc);
}

參考自:www.cnblogs.com/findumars/p/5574332.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM