2
我有一個類,如下所示:如何使用FreeImage_Unload(),並且不會丟失圖像數據
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),我失去的數據信息,如何我可以將'位'信息複製到'數據',所以無論何時卸載'dib'我都不會丟失信息?
有什麼建議嗎?
請注意,如果在音調中有填充,則爲malloc和memcpy中的長度計算使用GetPitch()x GetHeight()會更加正確 – StarShine