当前位置:网站首页>QT color extraction

QT color extraction

2022-06-13 01:21:00 Zhao_| adult

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

    qDebug()<<pixmap<<endl;
    int red, green, blue;
        if(!pixmap.isNull())
        {
    
            QImage image = pixmap.toImage();

            if(!image.isNull())
            {
    
                QColor color = image.pixel(0,0);
                red = color.red();
                green = color.green();
                blue = color.blue();

                // Output 16 The color of the base 
                //QString hRed = QString::number(red,16).toUpper();
                //QString hGreen = QString::number(green,16).toUpper();
                //QString hBlue = QString::number(blue,16).toUpper();
                
                // In this way, you can set the post conversion 16 The number of decimal digits : Less than digits 0 Add ;
                QString hRed =  QString("%1").arg(red,2,16,QLatin1Char('0')).toUpper();//value by int Type or char Both types are acceptable 
                QString hGreen =  QString("%1").arg(green,2,16,QLatin1Char('0')).toUpper();
                QString hBlue =  QString("%1").arg(blue,2,16,QLatin1Char('0')).toUpper();
                
                qDebug()<<red<<" "<<green<<" "<<blue<<endl;
                qDebug()<<hRed+hGreen+hBlue<<endl;
            }
        }

Refer to the connection : Heart like ten years
Refer to the connection :blueshaw

原网站

版权声明
本文为[Zhao_| adult]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280553073147.html