Qt ------ 截圖、獲取鼠標指定的RGB值


獲取RGB值思路:截圖,獲取圖片的(0,0)的RGB值

 

 

    int x = QCursor::pos().x();
    int y = QCursor::pos().y();
  // QPixmap pixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), x, y, 1, 1);

    QList<QScreen *> list_screen =  QGuiApplication::screens(); //可能電腦接了多個屏幕

    QPixmap pixmap = list_screen.at(0)->grabWindow(0,x,y,1,1);
    if (!pixmap.isNull()) //如果像素圖不為NULL
    {
        QImage image = pixmap.toImage();//將像素圖轉換為QImage
        if (!image.isNull()) //如果image不為空
        {
            if (image.valid(0, 0)) //坐標位置有效
            {
                QColor color = image.pixel(0, 0);
                mousedPressed_R = color.red();
                mousedPressed_G = color.green();
                mousedPressed_B = color.blue();
                QString text = QString("RGB: %1, %2, %3").arg(mousedPressed_R).arg(mousedPressed_G).arg(mousedPressed_B);
                qDebug() << text;
            }
        }
    }

 


免責聲明!

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



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