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

Author Topic: CSFML: access image / texture pixels  (Read 2004 times)

0 Members and 1 Guest are viewing this topic.

Mills

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
CSFML: access image / texture pixels
« on: January 21, 2020, 07:48:03 pm »
Is there any way to access the pixels of images and textures in CSFML without using setPixel, getPixel or sfImage_getPixelsPtr ?

Can I access the sfImage struct to get the pixels in CSFML or do I have to use the C++ SFML?

I'm asking this because sfImage_copyImage is not working the way I wanted.

For example I want to copy a "tile" (8x8 pixels) from a big image to a smaller one.

The following code should take the first 8x8 tile, (from 0,0 to 8,8 of the big image) and paste it to the top part of the small image.

Code: [Select]
sfImage_copyImage(Small_Image,Big_Image, 0, 0, (const sfIntRect){0, 0, 8, 8}, 0);

In my case, this just pastes the big image on top of the small one, ignoring the pixels that don't fit on the small image like a photoshop paste  :'(.

Maybe I'm using the sfImage_copyImage the wrong way?

Thanks!

EDIT: I really don't know why... But it worked inside a loop
Code: [Select]
int x = 0;int y = 0;int i = 0;
for (y = 0; y < 128; y+= 8){
for (x = 0; x < 128; x+= 8){
sfImage_copyImage(Tileset,New_Tileset, 0, i, (const sfIntRect){x, y, 8, 8}, 0);
i+= 8;
}
}

It loads all tiles correctly from a 128x128 image.

(I'm sorry I should have posted this in the graphics section).
« Last Edit: January 22, 2020, 12:50:11 am by Mills »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: CSFML: access image / texture pixels
« Reply #1 on: January 22, 2020, 08:47:00 am »
Quote
In my case, this just pastes the big image on top of the small one, ignoring the pixels that don't fit on the small image like a photoshop paste
Do you mean that the small image is a copy of the big image after this call (ie. it's bigger)?

Quote
I really don't know why... But it worked inside a loop
This code is not equivalent to the first one, so we can't draw any conclusion ;)

But the most important question is: why do you want to copy a single tile from a tileset to a separate image? This is often a wrong solution to a simple problem ;)
Laurent Gomila - SFML developer

Mills

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Re: CSFML: access image / texture pixels
« Reply #2 on: January 22, 2020, 10:21:59 pm »
I've been testing, I created a bug in my program which is now solved, so sfImage_copyImage had no issues  :).

 

anything