简体   繁体   中英

How can I find out how many bytes one pixel has in an CGImageRef?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM