SFML community forums
Help => Graphics => Topic started by: lefsler on November 25, 2014, 05:31:43 pm
-
Hi,
I need to resize a image and get each pixel (after the image is resized)..
I do the resize using
Texture tmpTexture;
tmpTexture.loadFromFile(tmp.str());
Sprite tmpSprite(tmpTexture);
tmpSprite.setScale(width/tmpSprite.getLocalBounds().width, height/tmpSprite.getLocalBounds().height);
But after that is possible to get the pixel after the resize operation is performed?
Regards
-
There are multiple ways to go about this. What exactly are you going to do with the pixel information?
-
i will generate some data about the R, G, B to do another stuff. In the end i am using the SFML library to do another thing, in the end i will just need to output 3 values to a text file, with (R, G, B).
-
The thing is sf::Texture "lives" on the GPU (https://github.com/SFML/SFML/wiki/FAQ#graphics-image-texture), thus the best way would be to write a shader program.
Otherwise you'll have to render the scaled sprite to a render texture and convert the extracted texture to an sf::Image to get to the pixel info. This can be slow.
-
If the idea is just to scale an image and then write it to a file in a new format, then I think I'd just use the convert tool from imagemagic and maybe a little python script for post-processing the text form.
-
The thing is sf::Texture "lives" on the GPU (https://github.com/SFML/SFML/wiki/FAQ#graphics-image-texture), thus the best way would be to write a shader program.
Otherwise you'll have to render the scaled sprite to a render texture and convert the extracted texture to an sf::Image to get to the pixel info. This can be slow.
How do i convert the RenderTexture to image or Texture to Image.
What i did was:
Texture tmpTexture;
tmpTexture.loadFromFile(tmp.str());
Sprite tmpSprite(tmpTexture);
tmpSprite.setScale(width/tmpSprite.getLocalBounds().width, height/tmpSprite.getLocalBounds().height);
sf::RenderTexture renderTexture;
renderTexture.create(width, height);
renderTexture.draw(tmpSprite);
Texture t=renderTexture.getTexture();
Image imageOut.... How do i convert?
-
There is only one method in the sf::Texture class (http://sfml-dev.org/documentation/2.1/classsf_1_1Texture.php) which returns an sf::Image, easy to find. :p
-
lol, thanks.
After i did that i try to save the image on a file (just to check the size) and i get.
JPEG parameter struct mismatch: library thinks size is 584, caller expects 568
What could be the problem?
The code is
Texture tmpTexture;
tmpTexture.loadFromFile(tmp.str());
Sprite tmpSprite(tmpTexture);
tmpSprite.setScale(width/tmpSprite.getLocalBounds().width, height/tmpSprite.getLocalBounds().height);
sf::RenderTexture renderTexture;
renderTexture.create(width, height);
renderTexture.draw(tmpSprite);
Texture t=renderTexture.getTexture();
Image imageOut =t.copyToImage();
tmp.str("");
tmp << "1" << entry->d_name;
imageOut.saveToFile(tmp.str());
cout << imageOut.getSize().x << endl;
cout << imageOut.getSize().y << endl;
tmp.str("");
-
Why does everybody always forget to call either clear() or display() when it comes to the render texture? ;D
For ever render target it's always clear, draw, display.
Googling the error message for like 1min told me, that your system most likely has a different version of libjpeg installed than the version SFML was built with. Are you on Linux?
Make sure the versions are the same.
-
Ohh, so to render the texture i need to add the
clear.
...draw here
display.
What version does SFML use of the libjpg?
-
Depends from where you got it and even more on with OS you are.