sfml resize image

Solutions on MaxInterview for sfml resize image by the best coders in the world

showing results for - "sfml resize image"
Chahine
30 Jun 2017
1/*
2sf::Image newImage = sf::Image();
3newImage.create(50, 50); // set size
4resizeImage(OldImage, newImage);
5
6*/
7
8void resizeImage(const sf::Image& originalImage, sf::Image& resizedImage)
9{
10    const sf::Vector2u originalImageSize{ originalImage.getSize() };
11    const sf::Vector2u resizedImageSize{ resizedImage.getSize() };
12    for (unsigned int y{ 0u }; y < resizedImageSize.y; ++y)
13    {
14        for (unsigned int x{ 0u }; x < resizedImageSize.x; ++x)
15        {
16            unsigned int origX{ static_cast<unsigned int>(static_cast<double>(x) / resizedImageSize.x * originalImageSize.x) };
17            unsigned int origY{ static_cast<unsigned int>(static_cast<double>(y) / resizedImageSize.y * originalImageSize.y) };
18            resizedImage.setPixel(x, y, originalImage.getPixel(origX, origY));
19        }
20    }
21}