如何在Qgraphicsview中裁剪图像?

发布于 2025-01-29 01:36:39 字数 137 浏览 4 评论 0原文

我必须开发一个图像编辑器。我缺少的最后一个功能是使用Qrubberband裁剪图像,然后使用按钮裁剪所选区域。

有报表有关qgraphicsView的报告,但我不知道如何将其连接到UI。

I have to develop an image editor. The last feature I'm missing for it is cropping the image using a QRubberBand, and then crop the selected area using a push button.

There are reports of subclassing QGraphicsView, but I don't know how to connect it to the UI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞梦里开花 2025-02-05 01:36:39

首先,您必须构建一个 qrect 与图片区域一起你想保留。

然后,您可以使用复制在qimage上的方法新图片仅包含矩形区域。

QRect rect(10, 10, 30, 30);  //X Y top left corner coordinates ,  width / height of the rectangle

QImage croppedImage = initialImage.copy(rect);

使用 qgraphicspixmapitem

  QGraphicsPixmapItem *unitaire = new QGraphicsPixmapItem();
   unitaire ->setPixmap(mySprite);
  m_scene->addItem(unitaire );

接下来

First you have to build a QRect with the area of the picture that you want to keep.

Then you can use the copy method on QImage to create a new picture containing only the rectangle area.

QRect rect(10, 10, 30, 30);  //X Y top left corner coordinates ,  width / height of the rectangle

QImage croppedImage = initialImage.copy(rect);

Next use a QGraphicsPixmapItem to add your picture in the scene :

  QGraphicsPixmapItem *unitaire = new QGraphicsPixmapItem();
   unitaire ->setPixmap(mySprite);
  m_scene->addItem(unitaire );

Good luck !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文