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

Author Topic: Image::LoadFromPixels() - Don't understand.  (Read 5781 times)

0 Members and 1 Guest are viewing this topic.

Jallen

  • Newbie
  • *
  • Posts: 39
    • View Profile
Image::LoadFromPixels() - Don't understand.
« on: June 29, 2010, 04:30:13 pm »
Hello. I'm accessing pixel data directly but just doing image.SetPixel() is too slow. I read a while back that it's faster to simply work on my own array and then use Image::LoadFromPixels().

The problem with this is I can't seem to figure out how to get my pixel data from my image (Image::GetPixelsPtr() looks like what I want but ???), into a workable array, and then back into my image...

So how do I do this?
I'm using SFML 1.6

Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Image::LoadFromPixels() - Don't understand.
« Reply #1 on: June 29, 2010, 05:55:30 pm »
Code: [Select]
sf::Image image;
// load/fill image...

// image --> your array
const sf::Uint8* ptr = image.GetPixelsPtr();
std::vector<sf::Uint8> pixels(ptr, ptr + image.GetWidth() * image.GetHeight() * 4);

// your array --> image
image.LoadFromPixels(image.GetWidth(), image.GetHeight(), &pixels[0]);
Laurent Gomila - SFML developer

Jallen

  • Newbie
  • *
  • Posts: 39
    • View Profile
Image::LoadFromPixels() - Don't understand.
« Reply #2 on: June 29, 2010, 06:01:29 pm »
That's precisely what I needed, thanks :D

Dominator

  • Newbie
  • *
  • Posts: 37
    • View Profile
Image::LoadFromPixels() - Don't understand.
« Reply #3 on: June 29, 2010, 10:08:20 pm »
Hi!

How can I achieve this in DotNet?

The Image constructor only accepts a 2-dimensional array of type Color, but the property "pixels" returns a byte array.

Shouldn't there be an easier way without having to convert the array?

Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Image::LoadFromPixels() - Don't understand.
« Reply #4 on: June 29, 2010, 10:50:13 pm »
I don't know .Net a lot, so this is probably not the best solution.

So you think that a 1D array would be better? Or both 1D and 2D?
Laurent Gomila - SFML developer

Dominator

  • Newbie
  • *
  • Posts: 37
    • View Profile
Image::LoadFromPixels() - Don't understand.
« Reply #5 on: June 30, 2010, 12:18:38 pm »
I can't say it for everyone but I for myself would prefer the 1D byte array.
In my opinion it's much easier to work with when sending over the network (the Image object is not serializable).

But pixel manipulation could probably be easier with the 2D array, no idea, I didn't need it yet.

Maybe make both possible 1D and 2D?
I for myself would be happy if the constructor accepted a byte array. :)

I think it could be a good idea to wait for other people's opinions. ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Image::LoadFromPixels() - Don't understand.
« Reply #6 on: July 01, 2010, 08:24:38 pm »
Quote
I think it could be a good idea to wait for other people's opinions.

I decided to add this new constructor
Code: [Select]
Image(uint width, uint height, byte[] pixels)
So now everyone will be happy ;)

It is available in SFML 2.
Laurent Gomila - SFML developer

 

anything