首先我想说我是一个完全的 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");
当前纹理和精灵定义如下。
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 的 ctor 引用 const
纹理实例。
如果您只对图像处理感兴趣,我建议您使用 SFML 以外的其他内容,因为您可能会为特定操作获得更好的功能/性能。可能是类似 imagemagick 的东西。
使用 SFML,你可以大致这样完成:
RenderTexture
- 将其视为一个虚拟窗口,当 .display()
被调用时,您可以访问它的纹理。display()
。sf::RenderTexture::getTexture()
并链接 copyToImage()
和 saveToFile()
。查看
sf::RenderTexture
的详细说明,了解使用示例。
您可以添加另一个
sf::Texture Newtexture = sprite.getTexture(); Newtexture.copyToImage().saveToFile("Something/Place/img.png");