当我将小图像添加到QGraphicsView时,有没有办法获得图像像素的坐标?我已经为我的自定义类QGraphicsView使用了橡皮筋,但我只能获得QGraphicsView坐标。
我想你想从给定的位置获得像素。假设给定的位置来自鼠标位置。
比方说,一个从QGraphicsView:继承的类
MyView::MyView( QWidget *parent=0 ) : QGraphicsView(parent)
{
setScene( new QGraphicsScene( this ) );
this->scene()->addPixmap(QPixmap::fromImage(this->image)); // this->image is a QImage
}
然后,实现鼠标事件
void MyView::mouseMoveEvent( QMouseEvent* event )
{
QPointF pos = mapToScene( event->pos() );
QRgb rgb = this->image.pixel( ( int )pos.x(), ( int )pos.y() );
}