[SDL] SDL_image

Ryan Hanlon ryanh at uidaho.edu
Wed Jan 26 10:16:43 PST 2005


Along with the flags, you should check the images BBP.  If it's 4 bytes, 
then your transparency is most likely stored in the alpha channel.  I 
don't know much about Irfanview, but most graphics programs I've used 
save PNGs with a full channel for transparency, since the format 
supports it.  And when SDL_image opens a PNG with transparency, it 
creates an RGBA surface rather than an RGB with color key flags.  If 
your image is loaded with an alpha channel, then you normally won't have 
to deal with the SDL_SRCPIXELCOLOR flag.  You might need to check for 
the SDL_SRCALPHA flag though.  I can't remember if SDL_image sets that 
flag for transparent PNGs or lets you do it yourself depending on how 
you intend to blit it.

Of course, if you know the color that's supposed to be transparent, you 
can also set the flags yourself after loading the image.

Ryan


paccy at t-online.de wrote:

>Hi,
>
>I have a problem with the SDL_image recognition for color keying.
>when I load an image saved with irfanview as png with transparency,
>no flags are set.
>I guess the should be SDL_SRCPIXELCOLOR set, or is there
>another way to distinguish between an image which has
>transparency set or not set ?
>
>Regards,
>  Thomas Omilian
>
>#include <iostream>
>#include <stdlib.h>
>#include <SDL.H>
>#include <SDL_Image.h>
>
>using namespace std;
>
>static const char *file = "c:\\image.png";
>SDL_Surface *img;
>
>int main(int argc, char *argv[])
>{
>   if
>(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER|SDL_INIT_CDROM) <
>0) {
>     exit(0);
>   }
>   img=IMG_Load(file);
>
>   if (img->flags==0) { 
>     cout <<"no flags set";
>   } else {
>     cout << "why did you get this message ?";
>   }
>   if (img!=NULL) {
>     SDL_FreeSurface(img);
>   } 
>   SDL_Quit();
>
>  return 0;
>}
>
>
>
>
>
>_______________________________________________
>SDL mailing list
>SDL at libsdl.org
>http://www.libsdl.org/mailman/listinfo/sdl
>  
>






More information about the SDL mailing list