How do I know how many bytes one pixel has in a CGImageRef?

The doc mentions CGBitmapContextGetBitsPerPixel (). I'm pretty sure I just need to divide this by 8.

But since I have not studied computer science, I am confused about the details. Does it matter if it's an 8-bit PNG or a 24-bit PNG? Or some other PNG?

So to get the safe bytes per pixel of the CGContextRef I would just split by 8?

0


a source to share


1 answer


The number of bits per pixel may not necessarily be a multiple of 8. Sometimes a 15-bit bit is used, as is 1-bit for black and white images. Therefore, if you want to find the minimum number of bytes needed to store a value for one pixel, divide it by 8 and round up.



+2


a source







All Articles