Hi, my goal is to visualize an image (e.g. in a QLabel), allow the use to select a portion of this image and visualize this portion in another QLabel. I have written the code, but I have a problem, the portion of image that I visualize is different from the selected part
CODE CPP
void Button1_nyq::on_selectimage_nyq_Hom_clicked()
{
Imagename
= QFileDialog::getOpenFileName(this,tr
("Open Image for Nyquist Test"),
"", tr
("Images (*.jpg)"));
//apro l'immagine //visualize the image in the first Label
ui->ImageDisplay->setPixmap(image); //ImageDisplay is the name of QLabel
}
int count_selection=0; ///when it is not 0 it mean that the user want to make another selection and I hide the previous
{
if(count_selection!=0)
rubberBand->hide();
point1 = e->pos();
}
{
rubberBand->show();
rubberBand
->setGeometry
(QRect(point1,e
->pos
()));
}
{
count_selection++;
QRect rect;
//selection rectangle rect.setTopLeft(point1);
rect.setBottomRight(e->pos()));
ui
->ImageDisplay
->render
(&image,
QPoint(0,
0),
QRegion(rect
));
//copy the selected part into "image" ui->label_image_selected->setPixmap(image); //show "image" in the second QLabel
void Button1_nyq::on_selectimage_nyq_Hom_clicked()
{
Imagename = QFileDialog::getOpenFileName(this,tr("Open Image for Nyquist Test"), "", tr("Images (*.jpg)")); //apro l'immagine
//visualize the image in the first Label
QPixmap image(Imagename);
ui->ImageDisplay->setPixmap(image); //ImageDisplay is the name of QLabel
}
int count_selection=0; ///when it is not 0 it mean that the user want to make another selection and I hide the previous
void Button1_nyq::mousePressEvent(QMouseEvent *e)
{
if(count_selection!=0)
rubberBand->hide();
point1 = e->pos();
rubberBand = new QRubberBand(QRubberBand::Rectangle,this );
}
void Button1_nyq::mouseMoveEvent(QMouseEvent *e)
{
rubberBand->show();
rubberBand->setGeometry(QRect(point1,e->pos()));
}
void Button1_nyq::mouseReleaseEvent(QMouseEvent *e)
{
count_selection++;
QRect rect; //selection rectangle
rect.setTopLeft(point1);
rect.setBottomRight(e->pos()));
QPixmap image(rect.size());
ui->ImageDisplay->render(&image,QPoint(0,0),QRegion(rect)); //copy the selected part into "image"
ui->label_image_selected->setPixmap(image); //show "image" in the second QLabel
To copy to clipboard, switch view to plain text mode
the actual results are:
Real image
http://imgur.com/9f6e0D3
Selected image
http://imgur.com/lysvM0q
Result
http://imgur.com/s0FydTc
How can I fix it?
Bookmarks