2

我有一个如下所示的类:

class myTexture
{
    public: 
        myTexture();
        ~myTexture();
        unsigned char * data;
        void loadFile(string file)
        {
            FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
            FIBITMAP *dib(0);
            BYTE* bits;

            fif = FreeImage_GetFileType(filename.c_str(), 0);
            if(fif == FIF_UNKNOWN) 
                fif = FreeImage_GetFIFFromFilename(filename.c_str());

            if(FreeImage_FIFSupportsReading(fif))
                dib = FreeImage_Load(fif, filename.c_str(), 0);

            bits = FreeImage_GetBits(dib);
            data = bits;
            FreeImage_Unload(dib);
        }
};

当我执行 FreeImage_Unload(dib) 时,我会丢失数据信息,如何将“bits”上的信息复制到“data”,以便在卸载“dib”时不会丢失信息?

有什么建议么?

4

1 回答 1

1

您必须将图像数据从 FreeImage 的 DIB 复制到单独的位置:

int Width  = FreeImage_GetWidth( dib );
int Height = FreeImage_GetHeight( dib );
int BPP    = FreeImage_GetBPP( dib ) / 8;
bits = FreeImage_GetBits( dib );
data = malloc( Width * Height * BPP );
memcpy( data, bits, Width * Height * BPP );

现在您可以随意释放了dib

于 2012-07-24T10:00:39.857 回答