比如我们要获取图片上某个点的颜色,要怎么处理呢?
1.获取鼠标坐标
2.截图并将坐标代入途中获取RGB(这里要考虑坐标不在范围)
假如是通过mousePressEvent获取到鼠标坐标
void mousePressEvent(QMouseEvent* e)
{
QPoint orgPoint;
orgPoint.setX(e->x());
orgPoint.setY(e->y());
QDesktopWidget* desk = QApplication::desktop();
QScreen* screen = QGuiApplication::primaryScreen();
QPixmap p = screen->grabWindow(desk->winId());
QImage image = p.toImage();
QColor color = image.pixelColor(sPos.x(), sPos.y());
int m_nRed = color.red();
int m_nGreen = color.green();
int m_nBlue = color.blue();
}
关于是不是在控件范围内
可以用eventFilter 或者contains