SFML community forums

Help => Graphics => Topic started by: Ago19 on February 15, 2022, 02:36:56 pm

Title: Resizing of an Image in SFML 2.5
Post by: Ago19 on February 15, 2022, 02:36:56 pm
I know that I can't resize an Image in SFML 2.5.
I learning how to use SFML and I'm trying to make a program that reads every pixel of an Image then transforms it into an ASCII char. The problem is that if the image size is too big the program takes too long and also can't output the whole pixel line to the console. (because in the console you can only output a fixed amount of char before it goes to the new line).
What I'm trying to do is to resize an Image. I tryied with sf::Image, sf::Texture but I can't with any of those. The only thing that i can resize is an sf::Sprite but then I can't take each pixel of the sprite with getPixel(x,y).
Any suggestions?
Thanks
Title: Re: Resizing of an Image in SFML 2.5
Post by: fallahn on February 15, 2022, 04:20:21 pm
Once you have your sprite and have resized it you can draw it to sf::RenderTexture (https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1RenderTexture.php) then use sf::RenderTexture::getTexture()::copyToImage()  (https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Texture.php#a77e18a70de2e525ac5e4a7cd95f614b9)to get it back to an image object. It can be slow but might be fast enough for what you need.
Title: Re: Resizing of an Image in SFML 2.5
Post by: Ago19 on February 16, 2022, 04:35:34 pm
How do I drawn on sf::RenderTexture? And then how do I use sf::RenderTexture::...?
Could you write me some example code? thanks

Title: Re: Resizing of an Image in SFML 2.5
Post by: eXpl0it3r on February 16, 2022, 04:50:34 pm
You can find some examples in the official documentation: https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1RenderTexture.php#details