圖片佔用內存的公式: numBytes = width * height * bitsPerPixel / 8;
OpenGL ES 紋理的寬和高都是按照 2 的次冪來計算的,一張圖片打實際大小是 480 * 320 ,在內存中的實際大小是成爲一張紋理爲 512 * 512的。
默認情況下,cocos2dx 加載一張圖片的時候,對於每一個像素點使用4個Byte來表示 1 個Byte(8位)代表Red,另外 3 個Byte分別代表 Green, Blue和 Alpha 透明通道,即 RGBA8888。
現在計算 512 * 512 * 32 / 8 = 1 MB(1 MB = 1024 KB = 1024B)
上面計算的也就是一張紋理大小爲 512 * 512 的圖片所在內存中所佔用的內存
PVRTC4: Compressed format, 4 bits per pixel, ok image quality
PVRTC2: Compressed format, 2 bits per pixel, poor image quality
一般pvr格式文件的圖像格式有:
RGBA8888: 32-bit texture with alpha channel, best image quality
RGBA4444: 16-bit texture with alpha channel, good image quality
RGB565: 16-bit texture without alpha channel, good image quality but no alpha (transparency)