Why is my image's Bytes per Row more than its Bytes per Pixel times its Width?

时光毁灭记忆、已成空白 提交于 2019-12-03 09:17:26

问题


I'm converting images to a MOV file, and had an interesting thing happen to me. I logged my bits per color component, bits per pixel, and bytes per row. Here's my code:

NSLog(@"Image width: %d, Height: %d", CGImageGetWidth(image), CGImageGetHeight(image));
NSLog(@"BPC: %d \ BPP: %d \ ByPR: %d", CGImageGetBitsPerComponent(image), CGImageGetBitsPerPixel(image), CGImageGetBytesPerRow(image));

Here's my output:

Image Width: 300, Height: 300 (everything's as expected) BPC: 8 (8 bits per color...so far so good) BPP: 32 (32 = 4 components ARGB * 8 bits per color...got it) ByPR:1216 (300 px per row * 4 bytes per pixel = 1200 bytes per row)

Why am I logged 1216 bytes per row, and not 1200? By the way, this isn't just a fluke. When I create a video based on those numbers for buffer sizes, it works. When I create it with 1200 bytes per row, I get some messed up aliasing effect.

Thoughts?!


回答1:


The system likes images to be a multiple of 64 bytes per row, presumably for better performance due to cache line alignment. 1200 is not a multiple of 64, but 1216 is.



来源:https://stackoverflow.com/questions/15935074/why-is-my-images-bytes-per-row-more-than-its-bytes-per-pixel-times-its-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!