模拟器和实际设备上的iPhone图像-不同的bitsPerPixel值?
我正在开发的iPhone应用程序中运行代码. 基本上,代码需要加载图像并调用:
I have code running in an iPhone application I am developing. Basically, the code needs to load an images and calls:
size_t bitsPerPixel = CGImageGetBitsPerPixel(imageRef);
我注意到在iPhone模拟器上,此调用返回24,而在设备本身上返回32.
I noticed that on the iPhone simulator this call returns 24 and the device itself it returns 32.
这是设计使然吗? 是我可以控制的东西吗?
Is this behavior by design? Is it something I can control?
我认为这取决于图像格式.
I think it comes down to the image format.
在iPhone应用程序中使用PNG时,为设备构建时,构建过程的一部分将通过pngcrush实用程序放置PNG图像,该实用程序会优化图像以供iPhone的图形处理器使用.这与以下事实有关:iPhone的图形处理器本身并不处理alpha,因此它依赖于预乘的alpha值.
When using PNGs in an iPhone app, part of the build process when building for device puts PNG images through the pngcrush utility, which optimises the images for use with the iPhone's graphics processor. It has something to do with the fact that the iPhone's graphic processor doesn't natively handle alpha, so it relys on pre-multiplied alpha values.
这可能是您所看到的差异.而且您在模拟器中看不到它的原因是,该模拟器使用Mac的grahics处理器,因此可以本地处理PNG中的Alpha,这意味着在构建过程中不会压碎" PNG.
This could be the difference you are seeing. And the reason you don't see it in the simulator is that the simulator uses the Mac's grahics processor, and therefore can natively handle alpha in PNGs, which means the PNGs aren't 'crushed' during the build process.
我认为...