3

I'm looking for a 2D image manipulation library for C++, ideally something modern which uses C++20.

Requirements:

  • works on Windows 10 (support for Windows filenames, mainly)
  • works with Visual Studio 2022 (no makefiles please)
  • simple to include (maybe header only; ideally just a few files), like GLFW if you know that
  • produces no or few warnings only, when being comiled
  • I only need basic operations like
    • get pixel / set pixel
    • draw line, ellipse and rectangle
  • support for PNG files (JPG and BMP welcome), reading and writing
  • gratis

Non-requirements:

  • displaying images on screen

I have tried:

  • Magick++
    • the site says it's up to Windows 7
    • the download location is unclear

      'win2k' subdirectory of the ImageMagick ftp site (and mirrors)

    • Visual Studio version is outdated

      ready-made Visual C++ 8.0 build environment

  • Leptonica
    • looks very C-ish, not C++-ish
2
  • Hi Thomas. I haven't tried Magick++ on Win10, but I've heard it will work as expected. Nov 24, 2022 at 8:17
  • @RockPaperLz-MaskitorCasket thanks for the suggestion. I hope I get another task that requires a graphics library so that I can test it as well. For now I implemented it with SFML (see answer below) and I liked it. Dec 5, 2022 at 12:36

1 Answer 1

0

I found SFML to suit my needs.

I really like the method names. They are straight forward, IMHO. Not cryptic or abbreviated.

For the requirements:

  • works on Windows 10

  • works with Visual Studio 2022.

    The download site mentions Visual Studio 2017 as the latest versions, but when I opened an issue on Github, the answer was that the VS2017 version is compatible with VS2019 and VS2022.

  • simple to include.

    The Tutorial for Visual Studio tells you what you need to do. Basically add some paths so that SFML can be found - stuff you know how to do when doing C++ development in Visual Studio.

  • get pixel / set pixel

    The code I used is as simple as

    sf::Image buffer;
    buffer.create(size, size, sf::Color(0, 0, 0));
    // some loop here
         buffer.setPixel(x, y, sf::Color::Green);

    buffer.saveToFile("test.png");
  • support for PNG files (JPG and BMP welcome), reading and writing

    Writing is definitely possible, see code before.

  • gratis

    zlib/png licensed

Displaying an image as a window was not so straight forward. It can't draw images on the window. It needs a sprite for that. And the Sprite needs a texture. I see that this may have benefit in game development and might speed up stuff if textures are reused. So the code is a little more complicated, but still ok:

    sf::RenderWindow window(sf::VideoMode(1000, 1000), "Visualization");

    sf::Image buffer;
    buffer.create(size, size, sf::Color(0, 0, 0));
    // Some loop here
        buffer.setPixel(x, y, sf::Color::Green);

    sf::Texture texture;
    texture.create(size,size);
    texture.update(buffer);

    sf::Sprite sprite;
    sprite.setTexture(texture);
    sprite.setPosition(sf::Vector2f(0.f, 0.f));
    sprite.scale(1000.f / size, 1000.f / size);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(sprite);
        window.display();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.