How can I find out how many bytes one pixel has in an CGImageRef?
-
21-08-2019 - |
Question
The doc is mentioning an CGBitmapContextGetBitsPerPixel(). I am almost sure that I would just have to divide this by 8.
But since I didnt study computer science, I am confused about the detail. Would it make a difference if it's an 8 bit PNG or 24 bit PNG? Or some other PNG?
So to get securely the bytes per pixel of an CGContextRef, would I just devide by 8?
Solution
The number of bits per pixel may not necessarily be a multiple of 8. 15-bit is sometimes used, as is 1-bit for black-and-white images. So if you want to find the minimum number of bytes required to hold the value for a single pixel, divide by 8 and round up.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow