QT:将位图/PNG 图像绘制到 QWidget

发布于 2024-11-02 03:30:33 字数 144 浏览 15 评论 0原文

我正在使用 C++ 中的 QT 构建游戏。我已将 QWidget 类扩展为绘画表面,并设置了一个线程来刷新屏幕。我现在需要的是从文件加载精灵表,将它们分解成单独的 64x64 像素图像,然后将它们绘制到屏幕上。有人对我应该如何做这件事有一些建议吗?

TIA

I am building a game using QT in c++. I have extended the QWidget class as a painting surface and have set up a thread to refresh the screen. What I need now is to load the sprite sheets from file, break them up into separate 64x64 pixel images, and then paint them to the screen. Does anyone have some advice for how I should go about doing this?

TIA

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

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

发布评论

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

评论(1

听,心雨的声音 2024-11-09 03:30:33

一些 QPainter::drawPixmap() 变体具有选项指定像素图中要绘制的矩形。这将帮助您保留精灵表而不将它们分解成小图像。

对于重复的精灵, QPainter::drawPixmapFragments() 可能会有更好的性能,而且允许子图像绘制。

Some QPainter::drawPixmap() variants has the option to specify the rectangle in the pixmap to be drawn. This will help you keeping the sprite sheets without breaking them up into small images.

For repeated sprites, QPainter::drawPixmapFragments() probably will have better performance and also allow sub-image drawing.

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