圖像占用內存的公式是:numBytes = width * height * bitsPerPixel / 8
OpenGL ES 紋理的寬和高都要是2次冪數, 以剛才的例子來說, 假如 start.png 本身是 480x320, 但在載入內存後, 它其實會被變成一張 512x512 的紋理, 而start.png 則由 101x131 變成 128x256, 默認情況下面,當你在cocos2d里面加載一張圖片的時候,對於每一個像素點使用4個byte來表示--1個byte(8位)代表red,另外3個byte分別代表green、blue和alpha透明通道。這個就簡稱RGBA8888
圖像寬度(width)×圖像高度(height)×每一個像素的位數(bytes per pixel) = 內存大小
此時,如果你有一張512×512的圖片,那么當你使用默認的像素格式去加載它的話,那么將耗費
512×512×4=1MB
1MB = 1024 KB= 1024*1024 B
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)