首先我想说我是一个完全的 C++ 新手。我不知道任何与之相关的词汇,所以如果这个问题是微不足道的,我很抱歉,因为我现在不知道正确的术语或短语来自己谷歌解决方案。
目前正在研究我在 github 上找到的这段代码,用于从我的 3ds 中捕捉游戏玩法。 https://github.com/Gotos/Cute3DSCapture/blob/master/main.cpp
我正在尝试添加旋转图像并将其保存到 png 文件的功能。
从 main.cpp
的第 267 行开始,我尝试添加以下功能。
sprite.setTexture(texture);
sprite.rotate(90);
texture = sprite.getTexture();
texture.copyToImage().saveToFile("Something/Place/img.png");
当前贴图和 Sprite 定义如下。
sf::Texture texture;
sf::Sprite sprite;
当我尝试构建和运行时,我得到以下结果
main.cpp:269:25: error: no viable overloaded '='
texture = sprite.getTexture();
~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~
/usr/local/include/SFML/Graphics/Texture.hpp:421:14: note: candidate function
not viable: no known conversion from 'const sf::Texture *' to
'const sf::Texture' for 1st argument; dereference the argument with *
Texture& operator =(const Texture& right);
如有任何帮助,我们将不胜感激。
最佳答案
sf::Sprite
不是纹理操纵器,这意味着 sf::Sprite::getTexture()
返回的纹理不会被修改。这就是 Sprite 的构造函数引用 const
纹理实例的原因。
如果您只对图像处理感兴趣,我建议您使用 SFML 以外的东西,因为您可能会为特定操作获得更好的特性/性能。可能类似于 imagemagick。
使用 SFML,你可以大致像这样:
- 创建
RenderTexture
所需大小——将其视为一个虚拟窗口,当.display()
被调用时,您可以访问它的纹理。 - 使用初始纹理和一些操作(例如旋转)创建 Sprite ——确保渲染纹理的大小正确设置为“显示”生成的图像
- 在渲染纹理上绘制您的 Sprite 并对其调用
display()
。 - 然后您可以调用
sf::RenderTexture::getTexture()
并链接copyToImage()
和saveToFile()
。
请查看sf::RenderTexture
的详细说明以获取使用示例。
关于c++ - 旋转纹理 sfml 并将输出保存到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35386108/