image weight
//this program open "image.png" and save screenshot "screenshot.png"
//to make screenshot press left arrow
#include <SFML/Graphics.hpp>
int main()
{
sf::Texture texture;
if (!texture.loadFromFile("image.png")){return 0;}
//windows size = texture size because i want to copy whole image
sf::Vector2u WindowSize = texture.getSize();
sf::RenderWindow window(sf::VideoMode(WindowSize.x,WindowSize.y), "SFML works!",sf::Style::Close);
sf::Image screenshot;
sf::Sprite sprite;
sprite.setTexture(texture);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
screenshot = window.capture();
screenshot.saveToFile("Screenshot.png");
}
}
window.clear(sf::Color::Transparent);
window.draw(sprite);
window.display();
}
return 0;
}
black image + if you minimize a window it turns black or white
int main()
{
sf::Texture texture;
if (!texture.loadFromFile("image.png")){return 0;}
//windows size = texture size because i want to copy whole image
sf::Vector2u WindowSize = texture.getSize();
sf::RenderWindow window(sf::VideoMode(WindowSize.x,WindowSize.y), "SFML works!",sf::Style::Close);
sf::Image screenshot;
sf::Sprite sprite;
sprite.setTexture(texture);
window.clear(sf::Color::Transparent);
window.draw(sprite);
window.display();
screenshot = window.capture(); //<<<<<<<<<<
screenshot.saveToFile("Screenshot.png"); //<<<<<<<<<<
return 0;
}
i tested it on this image
https://en.wikipedia.org/wiki/Portable_Network_Graphics#/media/File:PNG_transparency_demonstration_1.pngoriginal: 214 KB
screenshot: 330KB