Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Save a sf::Sprite  (Read 5591 times)

0 Members and 1 Guest are viewing this topic.

Dummie

  • Newbie
  • *
  • Posts: 25
    • View Profile
Save a sf::Sprite
« 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

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Save a sf::Sprite
« Reply #1 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...

Dummie

  • Newbie
  • *
  • Posts: 25
    • View Profile
Save a sf::Sprite
« Reply #2 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 :(

Xylankant

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • http://xylankant.xy.funpic.de
Save a sf::Sprite
« Reply #3 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.

Dummie

  • Newbie
  • *
  • Posts: 25
    • View Profile
Save a sf::Sprite
« Reply #4 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.

Xylankant

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • http://xylankant.xy.funpic.de
Save a sf::Sprite
« Reply #5 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...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Save a sf::Sprite
« Reply #6 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++ ;)
Laurent Gomila - SFML developer

 

anything