Save BMP(with alpha data) to PNG,alpha lost

yaoyansi
2010-01-09
2013-05-02
  • yaoyansi
    yaoyansi
    2010-01-09

    hi,
    I use devil1.7.8.
    I save a bmp texture which contains alpha data to PNG format, but the alpha data is lost in PNG file.
    here is my function:

    ILboolean LoadAndSaveToPNG( const string &from, const string &to)
    {
        ilInit();
        printf("DevIL has been initialized\n");
        // Loading an image
        ILboolean result = ilLoadImage( from.c_str() ) ;
        printf("load %s\n", from.c_str());
        if( result == IL_TRUE )
        {
            printf("the image loaded successfully\n");
        } else {
            printf("The image failed to load\n" ) ;
            ILenum err = ilGetError() ;
            printf( "error %d, error string:%s.\n", err, ilGetString( err ) );
            return IL_FALSE;
        }
        //  printf("save %s\n\n", to.c_str());
        //  string lowerformat(format);
        //  transform(format.begin(),format.end(),lowerformat.begin(),tolower);
        ILboolean bSave;
        bSave = ilSave( IL_PNG, to.c_str() ) ;
        assert( (bSave==IL_TRUE)&&"Save Error." );
        printf("\n");
        return bSave;
    }
    

    And here is my test project package.
    http://xyzhojo.googlecode.com/files/bmp2png.rar