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

Author Topic: Copy only part of an image. Help with copy function.  (Read 1616 times)

0 Members and 1 Guest are viewing this topic.

dixondean25

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Copy only part of an image. Help with copy function.
« on: March 10, 2014, 05:47:06 pm »
Is there a way to copy only part of an image into another image?
I don't get the copy function.
What is DestX and DestY? is it where the new image will stop copying pixels? If so, then i don't get the IntRect that is also passed and its purpose.

For example, i'm trying to create 3 different images from one image.
I'm setting the DestX and DestY to 0, which is probably wrong.
And then i'm setting the IntRect to the area i want the new image to copy from the image Maps.

Doing this result in an error in my command prompt: "Trying to access the pixels of an empty image"

I will keep trying though.

sf::Image Maps;
Maps.loadFromFile("MapSelect.png");
sf::Image map1;
map1.copy(Maps,0,0,sf::IntRect(0,0,640,360));
sf::Image map2;
map2.copy(Maps,0,0,sf::IntRect(640,0,640,360));
sf::Image map3;
map3.copy(Maps,0,0,sf::IntRect(1280,0,640,360));

dixondean25

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: Copy only part of an image. Help with copy function.
« Reply #1 on: March 10, 2014, 05:50:50 pm »
I've tried multiple solutions but i still can't get it to work.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Copy only part of an image. Help with copy function.
« Reply #2 on: March 10, 2014, 05:58:27 pm »
The error message gives a pretty good hint: you're trying to copy pixels into an empty image. The destination image won't automatically be expanded, you must create it with the correct size before copying anything into it.
Laurent Gomila - SFML developer

dixondean25

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: Copy only part of an image. Help with copy function.
« Reply #3 on: March 10, 2014, 06:19:08 pm »
Thank You! it works perfectly now.
I thought that the error was saying that the original image was empty, not the new ones.  :P

 

anything