• Advertisement
Sign in to follow this  

sfml, when loading images/textures ignore background color!?

This topic is 1919 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.
What i am trying to do is draw "Hero.png" 50x50 image to screen.
Problem is that i don't know how to ignore one color, so it does not draw a square of pink(color i use for background on "Hero.png" around my character. Therefore make the (255,0,255) color transparent on my sprite.

I cant find a function to do this in sfml.

in SDL the function is something like

//Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
//SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );

//int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key); This is definition

SDL_SetColorKey(MyImage,
SDL_SRCCOLORKEY,
SDL_MapRGB(Screen->format, 255, 0, 255);

Edited by BaneTrapper

Share this post


Link to post
Share on other sites
Advertisement
Why not open up your favorite photo editing program (paint.net is free and will do this), go to the magic wand tool (or use an eraser if you can't get paint.net) and select the pink, delete it. Unless your using MS Paint, it should be transparent when you save it. Why you'd use pink I don't know. If you don't have a magic wand here's how:

Use an eraser and delete all the pink. In SFML, you really can't do this without writing your own special and pointless line of code. However, I highly reccomend paint.net, because it makes doing this extremely easy.
EDIT:
The magic wand is a photo editing tool, google it. Edited by superman3275

Share this post


Link to post
Share on other sites

Why not open up your favorite photo editing program (paint.net is free and will do this), go to the magic wand tool (or use an eraser if you can't get paint.net) and select the pink, delete it. Unless your using MS Paint, it should be transparent when you save it. Why you'd use pink I don't know. If you don't have a magic wand here's how:

Use an eraser and delete all the pink. In SFML, you really can't do this without writing your own special and pointless line of code. However, I highly reccomend paint.net, because it makes doing this extremely easy.
EDIT:
The magic wand is a photo editing tool, google it.


Well if that is the case ok then. And thank you!
Already edit all my images. Did it with gimp...
Again thanks you very much on fast reply. Edited by BaneTrapper

Share this post


Link to post
Share on other sites
If you already have images keyed to a certain color, you can set that color to be transparent using createMaskFromColor()

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Image.php#a22f13f8c242a6b38eb73cc176b37ae34

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement