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

Author Topic: How to copy a part of an image?  (Read 2665 times)

0 Members and 1 Guest are viewing this topic.

nbd

  • Newbie
  • *
  • Posts: 14
    • View Profile
How to copy a part of an image?
« on: March 18, 2014, 03:46:45 pm »
Is there a way to initialize an image (sf::Image or sf::Texture ) with only a portion (region) of other image? Say, one have a source 1000x1000 image and a destination 100x100 image. Is there a way to copy into the destination image a 100x100 region of the source image with specified coordinates?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: How to copy a part of an image?
« Reply #1 on: March 18, 2014, 03:53:28 pm »
Did you even care to look at the documentation? ;)

The sf::Image has a copy function that lets you do so.

For textures you can specify an area to be loaded (see here), but if you want to change it later, you might want to use a texture rect in a sprite, otherwise you'll have to go via a render texture, which might not always be what you want.
« Last Edit: March 18, 2014, 03:57:56 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nbd

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to copy a part of an image?
« Reply #2 on: March 18, 2014, 04:10:23 pm »
Thankx! (I read documentation about Image, but looked only to constructors since I thought that if there is way to copy a part of an image, it would be logical to have a constructor with such an option. )

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: How to copy a part of an image?
« Reply #3 on: March 18, 2014, 06:10:23 pm »
Thankx! (I read documentation about Image, but looked only to constructors since I thought that if there is way to copy a part of an image, it would be logical to have a constructor with such an option. )
SFML tends to have lots of stuff in functions rather than in the constructor, just for future reference.