开发者

CGImageGetBytesPerRow() returns different values on iOS simulator and iOS Device

开发者 https://www.devze.com 2023-03-02 18:32 出处:网络
I have an image taken by my ipod touch 4 that\'s 720x960. In the simulator calling CGImageGetBytesPerRo开发者_如何学编程w() on the image returns 2880 (720 * 4 bytes) which is what I expected.However o

I have an image taken by my ipod touch 4 that's 720x960. In the simulator calling CGImageGetBytesPerRo开发者_如何学编程w() on the image returns 2880 (720 * 4 bytes) which is what I expected. However on the device CGImageGetBytesPerRow() will return 3840, the "bytes per row" along the height. Does anyone know why there is different behavior even though the image I'm CGImageGetBytesPerRow() on has a width of 720 and height of 960 in both cases?

Thanks in advance.


Bytes per row can be anything as long as it is sufficient to hold the image bounds, so best not to make assumptions that it will be the minimum to fit the image.

I would guess that on the device, bytes per row is dictated by some or other optimisation or hardware consideration: perhaps an image buffer that does not have to be changed if the orientation is rotated, or the image sensor transfers extra bytes of dead data per row that are then ignored instead of doing a second transfer into a buffer with minimum bytes per row, or some other reason that would only make sense if we knew the inner workings of these devices.


It may slightly different because the internal memory allocation: "The number of bytes used in memory for each row of the specified bitmap image (or image mask)."1

Consider using NSBitmapRepresention for some special tasks.

0

精彩评论

暂无评论...
验证码 换一张
取 消