如何在SFML C++中传递图像
How to pass an Image in SFML C++
我正在尝试制作一个简单的函数或类,该函数或类选择一个图像并返回它,或者以某种方式将它传递给另一个类。它是否像知道图像是什么类型一样简单?还是我需要做点别的?我正在Windows8计算机上运行带有GNUGCC编译器的Code::Blocks 10.05。感谢您的帮助。
多亏了唯美主义,我取得了一些进步。现在我有了这个:
class Background{
sf::Image BGI;
sf::Sprite BG;
Image& img;
public:
void rimage(std::string name){
sf::Image extra;
extra.LoadFromFile(name);
img = extra;
}
void init(std::string name){
BGI = img
BG.SetPosition(0.f,0.f);
BG.SetImage(BGI);
}
};
但当我运行它时,我会得到这个:
...4 error: ISO C++ forbids declaration of 'Image" with no type
此外,
...10 error: 'img' is defined in this scope
我已经包含了运行SFML所需的库,我只是把它放在一边以保持干净,我调整了上面发生错误的行,使其更容易遵循。
img现在不是后台中的一个全局变量吗?我认为CCD_ 1是CCD_。。。这里需要改变什么?
您不需要load
方法,也不需要任何额外的Image
对象。您可以在构造函数中完成所有这些处理。
class Background{
private:
// You only need an image and a background, if that.
sf::Image BGI;
sf::Sprite BG;
public:
// Use a constructor.
Background(std::string name)
{
SetBackground(name, Vector2f(0.f, 0.f));
}
void SetBackground(std::string name, sf::Vector2f pos)
{
BGI.LoadFromFile(name);
BG.SetImage(BGI);
BG.SetPosition(pos);
}
};
// Constructor loads image, sets image to sprite, and set sprite position.
Background bg("MyBackground.png");
// You can change the background image an position like so.
bg.SetBackgrond("newImage.png", Vector2f(10.f, 20.f));
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 平均图像时图像损坏
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- Vulkan验证层不断在VkQueuePresentKHR()上抛出图像布局错误
- 使用FFMPEG将RGB图像序列保存到.mp4时出现问题
- 将RGB图像保存为PPM格式
- 将图像添加到资源文件夹UWP C++
- 彩色图像的卤化物处理平均值
- C++射线示踪剂ppm表示没有足够的数据来显示图像
- 重新定位图像时如何前进到下一个内存块
- 如何使用按钮更新GTK3图像以使用C++从相机捕获图片
- 为什么 BMP 图像上的 imwrite 会卡住/不返回?
- Gstreamer:每 5 秒使用多文件墨水保存图像/jpeg
- 如何使用CImg打开图像?
- 如何使用 OpenCV 解码在两个 UWP 应用之间发送的图像字节?
- 使用 CUDA 和纹理进行图像减法