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

Author Topic: [HOWTO] Can I get bitmap from sf::Image?  (Read 2000 times)

0 Members and 2 Guests are viewing this topic.

rapide

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
[HOWTO] Can I get bitmap from sf::Image?
« on: July 24, 2012, 06:08:01 pm »
Hello!

I have a question... Can I get bitmaps from sf::Image instances and then save those to binary file? I want to create something likes images library in one file.

I would be grateful for any help.

rapide :-)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: [HOWTO] Can I get bitmap from sf::Image?
« Reply #1 on: July 24, 2012, 06:16:31 pm »
You know there exists a documentation for such kind of questions, e.g. here! ::)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rapide

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: [HOWTO] Can I get bitmap from sf::Image?
« Reply #2 on: July 24, 2012, 06:26:37 pm »
Yes, I know that I have documentation and I can read but I asked a question... I was trying to use const Uint8* GetPixelsPtr () const; but didn't know how to use const Uint8*.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: [HOWTO] Can I get bitmap from sf::Image?
« Reply #3 on: July 24, 2012, 06:56:56 pm »
Then you should ask the question right. ;)
So the problem is not how to get the image but how to use the function or better the returned type.

GetPixelsPtr() returns the pointer to the first element of the pixel array that represents the image, it has the size  GetWidth() x GetHeight() x 4 as stated in the documentation.
Now you can itereate over it and do what ever you want with the pixel information.

Additionally it seems like you're using SFML 1.6. I adivce you to use SFML 2, because 1.6 is waaay outdated.


(Btw @Laurent if you're reading this, the doc in SFML 2 also says 'GetWidth() * GetHeight() * 4' although it's now 'getSize().x x getSize().y x 4')
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rapide

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Re: [HOWTO] Can I get bitmap from sf::Image?
« Reply #4 on: July 24, 2012, 07:14:05 pm »
Thanks for good advice. I used 1.6 version but I'll change it :)

 

anything