为什么我的图像的每行字节数超过其每像素的字节数乘以其宽度? [英] Why is my image's Bytes per Row more than its Bytes per Pixel times its Width?

查看:97
本文介绍了为什么我的图像的每行字节数超过其每像素的字节数乘以其宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将图像转换为MOV文件,并且有一件有趣的事情发生在我身上。我记录了每个颜色分量的位数,每像素位数和每行字节数。这是我的代码:

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));

这是我的输出:

图像宽度:300,高度:300(一切都如预期的那样)
BPC:8(每种颜色8位......到目前为止这么好)
BPP:32(32 = 4种成分ARGB *每种颜色8位。 ..)
ByPR:1216(每行300 px *每像素4个字节=每行1200个字节)

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)

为什么我记录每个1216个字节排,而不是1200?顺便说一句,这不仅仅是一个侥幸。当我根据缓冲区大小的数字创建视频时,它可以工作。当我用每行1200字节创建它时,我得到一些混乱的混叠效果。

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.

想法?!

推荐答案

系统喜欢图像是每行64字节的倍数,可能是因为缓存行对齐而获得更好的性能。 1200不是64的倍数,但1216是。

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.

这篇关于为什么我的图像的每行字节数超过其每像素的字节数乘以其宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆