SFML community forums

Help => Graphics => Topic started by: Dummie on July 08, 2008, 06:30:20 pm

Title: Save a sf::Sprite
Post by: Dummie on July 08, 2008, 06:30:20 pm
Hey,

is there any way to save a sf::Sprite?

Code: [Select]

sf::Sprite spr(img);
sf::Rect<int> rect;
rect.Left = imgX1;
rect.Right = imgX2;
rect.Bottom = imgY2;
rect.Top = imgY1;
spr.SetSubRect(rect);
spr.Resize(32, 32);
// Save???


I need to save it to a png file to continue working with it.

Thanks in advance,
Dummie
Title: Save a sf::Sprite
Post by: quasius on July 08, 2008, 07:09:06 pm
No, but I remember seeing a save function for images.

Edit:  If all you want is to save a cropped and resized image, MSPaint can do that...
Title: Save a sf::Sprite
Post by: Dummie on July 08, 2008, 07:39:12 pm
Yes, you are right. But sf::Image hasn't possibilites to rescale and so on...

Yes I just want to saave a cropped and resized image. But I want to do it for much images! I hoped I could do it with SFML. Imagine, I even can. But I cant save my results :(
Title: Save a sf::Sprite
Post by: Xylankant on July 08, 2008, 08:10:15 pm
Well, you could work around that by generating a Window for the scaled Image (same size etc.) and then taking a screenshot, which you can easily safe on your harddisk.
Title: Save a sf::Sprite
Post by: Dummie on July 08, 2008, 08:57:41 pm
Quote from: "Xylankant"
Well, you could work around that by generating a Window for the scaled Image (same size etc.) and then taking a screenshot, which you can easily safe on your harddisk.


I tried so already but I get very ugly results then. I must save it without to create a window.
Title: Save a sf::Sprite
Post by: Xylankant on July 08, 2008, 10:13:23 pm
mhhh, I'm not sure, however, I don't think there's such a function in SFML (it's just not what SFML is designed for in the first place ;) )

But I think that scaling the Image (respectively the Sprite) in SFML will give you the same result as scaling it with any other program...what counts, is the size of the original image, e.g. if you want to resize from 10*10 pixels to 800*600 pixels, the result *will* indeed be rather ugly ;)

edit: trying what I just wrote, I must say that it in fact does, what I predicted...the quality of my scaled images is just as if I had scaled them with paint or whatever...
However, I came across another problem: with my "workaround", you can only scale images up to you actual screen-resolution, because for any reasons, RenderWindows won't display if they oversize your screen...
Title: Save a sf::Sprite
Post by: Laurent on July 09, 2008, 02:54:25 am
Xylankant is right, SFML is not designed for that. You'd rather use an image manipulation library, there are tons of them available in C++ ;)