为什么像素不改变颜色
Why pixel is not changing color
我使用SFML库在C 上(C 的零经验(进行伪涂料。我做了一个单独的功能来编辑图像,"工具0"基本上是铅笔。当我尝试将其传递给我的函数时,它行不通,但是当我这样做而不将其传递给绘制图像功能时,它正常起作用。我在提出的代码上删除了额外的零件
我试图将鼠标位置的x和y作为单独的args传递(不使用向量(,但这无济于事
void drawOnImage(sf::Color color, int tool, sf::Texture canvas, sf::Image image, sf::Vector2i vector);
int main()
{
sf::Image image;
image.create(windowWidth, windowHeight, sf::Color::White);
sf::Texture canvas;
sf::Color currentColor = sf::Color::Black; // Color
int currentTool = 0; // instrument that is currently chosen
sf::Sprite sprite;
int mousedown = 0;
mainWindow.setFramerateLimit(60);
canvas.loadFromImage(image);
sprite.setTexture(canvas);
while (mainWindow.isOpen())
{
canvas.loadFromImage(image);
sf::Event event;
while (mainWindow.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
mainWindow.close();
else if ((event.type == sf::Event::MouseMoved) && (mousedown == 1))
{
canvas.update(mainWindow);
drawOnImage(currentColor, currentTool, canvas, image, sf::Mouse::getPosition(mainWindow));
}
else if (event.type == sf::Event::MouseButtonPressed)
{
mousedown = 1;
drawOnImage(currentColor, currentTool, canvas, image, sf::Mouse::getPosition(mainWindow));
//image.setPixel(sf::Mouse::getPosition(mainWindow).x, //IT WORKS but drawOnImage does not
sf::Mouse::getPosition(mainWindow).y, sf::Color::Black);
}
void drawOnImage(sf::Color color, int tool, sf::Texture canvas, sf::Image image,sf::Vector2i vector) {
if (tool == 0) {
image.setPixel(vector.x,vector.y, sf::Color::Black);
}
}
我敢肯定,我根本不知道一些C 功能,例如传递对象的地址而不是名称,但是我自己无法弄清楚
修改图像后,您需要再次将其加载到纹理上,因此您需要再次调用此行:
canvas.loadFromImage(image);
相关文章:
- 当我使用CHAR_INFO结构时,控制台会无缘无故地改变颜色
- SDL2 加载某些纹理会使SDL_RenderFillRect颜色变得奇怪
- 为什么像素不改变颜色
- 旋转三角形并在opengl中改变其颜色
- cocos2d-x beta3 LayerColor 不会改变背景颜色
- OpenGL改变生成的纹理的颜色
- QPainter 不会改变颜色
- C++图像库 - 找到一种颜色的像素并使它们变白,其他一切都变黑
- 我如何在c++中改变颜色
- 在QLineEdit中改变帧的颜色
- 如何使用OpenGL和GLSL来改变颜色(c++)
- glColor实际上并没有改变OpenGL的颜色
- 改变一个MFC对话框元素的背景颜色
- 标题名称不显示,背景颜色不改变
- BPP颜色改变SDL
- 如何制作一个当用户按下某些键时改变颜色的正方形
- 如何改变从标题(水平/垂直)QTableWidget在Qt的背景颜色
- c++ win32改变轨迹栏背景颜色
- 通过点击改变字体的颜色
- 传递指针以改变其值但保持不变