c++ - Cropping an image on Qt -
i'm building simple image editor on qt.i have opened image on qgraphicsview , want able crop it.after lot of search came code doesn't work.
void mainwindow::on_openbutton_pressed() { qstring imagepath=qfiledialog::getopenfilename(this,tr("open file"),"",tr("jpeg (*.jpg *.jpeg);;png (*.png)")); imageobject=new qimage(); imageobject->load(imagepath); image=qpixmap::fromimage(*imageobject); scene = new qgraphicsscene(this); scene->addpixmap(image); scene->setscenerect(image.rect()); ui->graphicsview->setscene(scene); ui->graphicsview->setdragmode(qgraphicsview::rubberbanddrag); showevent(); } void mainwindow::mousepressevent(qmouseevent *event){ start=event->pos(); } void mainwindow::mousereleaseevent(qmouseevent *event) { end=event->pos(); } void mainwindow::on_cropbutton_clicked() { start=ui->graphicsview->mapfromscene(start); end=ui->graphicsview->mapfromscene(end); qrect rect(start, end); cropped.size()=rect.size(); cropped=image.copy(rect); ui->graphicsview->scene()->addpixmap(cropped); ui->graphicsview->scene()->setscenerect(cropped.rect()); showevent(); }
can find mistake or propose better way it? thank lot.
Comments
Post a Comment