CGBitmapContextCreate Supported Color Spaces

Q: What color spaces does CGBitmapContextCreate support?

A: CGBitmapContextCreate supports the following combinations for the colorspace (CS), bitsPerComponent (BPC), and alphaInfo parameters:

Note: This document has been superseded by the Quartz 2D Programming Guide. A table describing the currently supported pixel formats for a bitmap context is contained in the section that covers the creation of bitmap contexts. The rest of this Q&A represents valid parameter combinations available on Mac OS X 10.3 or later only.

Table 1: Supported Combinations

CSBPCalphaInfoResulting Bits and Description
NULL8kCGImageAlphaOnlyAAAAAAAA

8 bits per pixel alpha-only destination. Color data is thrown away. Useful for generating alpha-only bitmaps and masks.

Available in Mac OS X 10.3 and later.
Gray8kCGImageAlphaNoneWWWWWWWW

8 bits per pixel grayscale channel.
RGB5kCGImageAlphaNoneSkipFirst-RRRRRGGGGGBBBBB

16 bits per pixel, 5 bits per RGB component.
RGB8kCGImageAlphaNoneSkipFirst--------RRRRRRRRRGGGGGGGGBBBBBBBB

32 bits per pixel, 8 bits per RGB component where first 8 bits are ignored.
RGB8kCGImageAlphaNoneSkipLastRRRRRRRRRGGGGGGGGBBBBBBBB--------

32 bits per pixel, 8 bits per RGB component where last 8 bits are ignored.
RGB8kCGImageAlphaPremultipliedFirstAAAAAAAARRRRRRRRRGGGGGGGGBBBBBBBB

32 bits per pixel, 8 bits per ARGB component with premultiplied alpha.
RGB8kCGImageAlphaPremultipliedLastRRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA

32 bits per pixel, 8 bits per RGBA component with premultiplied alpha.
CMYK8kCGImageAlphaNoneCCCCCCCCMMMMMMMMYYYYYYYYKKKKKKKK

32 bits per pixel, 8 bits per CMYK component without alpha.

Available in Mac OS X 10.3 and later.

Note: To create an alpha-only bitmap context simply pass NULL for the colorspace parameter. Q&A 1369 describes how to create RGB, CYMK, Gray, and other color spaces while maintaining color matching.

Table 2: and the resulting bits are designated as follows:

BitDescription
WWhite
AAlpha
RRed
GGreen
BBlue
CCyan
MMagenta
YYellow
KBlack
-Skip

Document Revision History

DateNotes
2007-07-18Updated to point to the Quartz 2D Programming Guide, minor text changes.
2005-10-04Updated to point to the Q&A describing how to properly create color spaces. Added a note that this Q&A is only valid for formats introduced in 10.3 and earlier.
2004-09-09Removed two combinations in the Gray color space that had been incorrectly documented as supported.
2004-02-20Lists the color space and alpha info combinations currently supported by CGBitmapContextCreate.

Posted: 2007-07-18


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.