如何从 QImage (Qt 4.6) 中裁剪多边形(用多图像填充)

发布于 2024-10-08 19:19:48 字数 371 浏览 0 评论 0原文

OS::win xp sp3

Qt::4.6

我正在开发基于 Qt 框架的 PUZZLE 游戏,需要一些帮助。

项目中包含主图片,需要将其分解为更小的部分(具有属于它们的图像的多边形)。因此,我制作图像 QImage image = QImage("someImage.jpg") 并希望在该对象上进行诸如裁剪图像之类的操作。

我检查了 QImageQPixmap... 诺基亚网站上的文档,寻找成员函数。与裁剪类似,但发现为零。

需要参考类我必须使用( #include )来解决这个问题,然后我将重新检查在线文档。

OS::win xp sp3

Qt::4.6

I am working on the PUZZLE game based on Qt framework and need some help.

In project is included main picture which needs to be disassembled to smaller parts (polygons with images belongig to them). So I make image QImage image = QImage("someImage.jpg") and want to operate with something like croping image on that object.

I checked QImage, QPixmap... docu on nokia site looking for member func. similar to croping but found zero.

Need reference to class I must use ( #include <???> ) to solve this problem and then I will recheck online docu.

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

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

发布评论

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

评论(3

空心↖ 2024-10-15 19:19:48

假设原始图像称为 A。您有一个多边形 P。您想要创建一个较小的图像 B,该图像基本上是 A 被 P“裁剪”的。步骤如下:

  • 创建 B。要知道大小,只需使用 QPolygonF:: P 上的边界矩形。
  • 用透明颜色或任何您想要的背景颜色填充 B。
  • 创建一个适用于 B 的新 QPainter
  • 将绘制器剪辑路径设置为 P(多边形可以转换为路径),请参阅 QPainter::setClipPath
  • 使用绘制器绘制 A

请注意,如果 P 的边界矩形不在 P 中,则可以平移绘制器起源。

Supposed the original image is called A. You have a polygon P. You want to create a smaller image B which is basically A "cropped" by P. Here are the steps:

  • Create B. To know the size, just use QPolygonF::boundingRect on P.
  • Fill B with transparent color or whatever background color you want to have.
  • Creates a new QPainter that works on B
  • Sets the painter clip path to P (polygon can be converted path), see QPainter::setClipPath
  • Draws A using the painter

Note that you might translate the painter if the bounding rect of P is not in the origin.

浅黛梨妆こ 2024-10-15 19:19:48

您可以使用 QImage 的这些成员

QImage  copy ( const QRect & rectangle = QRect() ) const
QImage  copy ( int x, int y, int width, int height ) const

You may use these members of QImage

QImage  copy ( const QRect & rectangle = QRect() ) const
QImage  copy ( int x, int y, int width, int height ) const
要走干脆点 2024-10-15 19:19:48

您应该使用 QPixMap:使用它您可以将原始图像的全部或部分复制到拼图部分中。通过用透明颜色绘制这些部分,您可以使多边形的外部变得不可见。或者您将 bitBlt(Qt 3 支持成员)与 QImage 一起使用以获得相同的效果。

You should use a QPixMap: With it you can copy all or parts of the original image into your puzzle parts. By painting into these parts with a transparent color you can make the outside of your polyongs invisible. Or you use bitBlt (Qt 3 Support Member) with QImage for the same effect.

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