# SetColorKey & SDL\_image

**URL:** <https://discourse.libsdl.org/t/setcolorkey-sdl-image/6053>\
**Category:** SDL Development\
**Created:** [February 23, 2002, 5:27pm UTC](https://discourse.libsdl.org/t/setcolorkey-sdl-image/6053 "2002-02-23T17:27:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Thielen](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/ce73a5/32.png) [@Christopher\_Thielen](https://discourse.libsdl.org/u/Christopher_Thielen)\
**Post date:** [February 23, 2002, 5:27pm UTC](https://discourse.libsdl.org/t/setcolorkey-sdl-image/6053/1 "2002-02-23T17:27:01Z")

</div>

I’m using SDL\_SetColorKey to make any pixel that is 0,0,255 (ugly blue)  
fully transparent, and this worked fine while I was using SDL\_LoadBMP w/  
BMPs. Now I’m using SDL\_image and those images are PNG. I converted them  
to PNG using GIMP and simply changed the surface =  
SDL\_LoadBMP(“filename.bmp”) to surface = IMG\_Load(“filename.png”). Now  
SetColorKey seems to not do anything, and the blue isn’t going away. I  
thought maybe it was the PNG compression changing the pixel color, but  
when I open those same PNGs in GIMP, GIMP reports they are 0,0,255 for  
sure.

Any ideas as to why SetColorKey doesn’t work? Here’s an example of what  
I’m doing:

temp = IMG\_Load(“images/pointer.png”);  
SDL\_SetColorKey(temp,  
SDL\_SRCCOLORKEY | SDL\_RLEACCEL,  
(Uint16) SDL\_MapRGB(temp-\>format, 0, 0, 255));  
pointer = SDL\_DisplayFormat(temp);  
SDL\_FreeSurface(temp);

But now, pointer still has all the 0,0,255 pixels showing. Any ideas as  
to why?–

- Chris  
Epiar Administrator/Programmer  
[http://epiar.sourceforge.net/](http://epiar.sourceforge.net/)

---

<div class="post-metadata">

**Author:** ![Rainer\_Deyke](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/r/a9a28c/32.png) [@Rainer\_Deyke](https://discourse.libsdl.org/u/Rainer_Deyke)\
**Post date:** [February 23, 2002, 6:41pm UTC](https://discourse.libsdl.org/t/setcolorkey-sdl-image/6053/2 "2002-02-23T18:41:00Z")

</div>

“Christopher Thielen” wrote in message  
news:mailman.1014514024.31717.sdl at [libsdl.org](http://libsdl.org)…

> SDL\_SetColorKey(temp,  
> SDL\_SRCCOLORKEY | SDL\_RLEACCEL,  
> (Uint16) SDL\_MapRGB(temp-\>format, 0, 0, 255));

‘SDL\_MapRGB’ returns an ‘Uint32’ and ‘SDL\_SetColorKey’ accepts an  
‘Uint32’, so why are you casting to ‘Uint16’?–  
Rainer Deyke | root at [rainerdeyke.com](http://rainerdeyke.com) | [http://rainerdeyke.com](http://rainerdeyke.com)
