Platforms to show: All Mac Windows Linux Cross-Platform

CGBitmapContextCreateMBS(data as memoryblock, width as Integer, height as Integer, bitsPerComponent as Integer, bytesPerRow as Integer, colorspace as CGColorSpaceMBS, alphaInfo as Integer) as CGBitmapContextMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
global method CoreGraphics MBS MacCG Plugin 3.4 ✅ Yes ❌ No ❌ No ✅ Yes All
Create a bitmap context.

The context draws into a bitmap which is 'width' pixels wide and 'height' pixels high. The number of components for each pixel is specified by 'colorspace', which also may specify a destination color profile. The number of bits for each component of a pixel is specified by 'bitsPerComponent', which must be 1, 2, 4, or 8. Each row of the bitmap consists of 'bytesPerRow' bytes, which must be at least '(width * bitsPerComponent * number of components + 7)/8' bytes. 'data' points a block of memory at least 'bytesPerRow * height' bytes. 'alphaInfo' specifies whether the bitmap should contain an alpha channel, and how it's to be generated.

Fails if data=nil or colorspace=nil.
The memoryblock is not referenced and not stored, so keep it alive while using the BitmapContext object.

Returns nil on any error.

data
A pointer to the destination in memory where the drawing is to be rendered. The size of this memoryblock should be at least(bytesPerRow*height) bytes.

width
The width of the bitmap in pixels.

height
The height of the bitmap in pixels.

bitsPerComponent
The number of bits to use for each component of a pixel in memory. Allowable values are 4, 5, or 8. For example, for a 32-bit RGB(A) colorspace, you would specify a value of 8 bits per color component. In combination, the number of bits per component, the color space, and the alpha value determine which bitmap context formats Quartz supports.

bytesPerRow
The number of bytes of memory to use per row of the bitmap. This value must be at least the product of the width and bitsPerComponentparameters, times the number of components per pixel. The result should be divided by 8 and rounded up to the nearest whole number to obtain the number of bytes to use per row. That is, the value must be at least (((width)*(bits per component)*(number of components per pixel))+7)/8 bytes. For a given row, Quartz stores bitmap data for the first width pixels and ignores any remaining bytes. The colorspace value referenced by the colorspace parameter specifies the number of components for each pixel.

colorspace
The color space to use for the bitmap context.

alphaInfo
A CGImageAlphaInfo constant specifying whether the bitmap should contain an alpha channel and how it is to be generated. The alpha value determines the opacity of a pixel when it is drawn.

Supported pixel formats:

Pixel formatColor spaceBits per pixelBits per componentAlpha option
Gray_8Grayscale88kCGImageAlphaNone
RGB555RGB165kCGImageAlphaNoneSkipFirst
XRGB_32RGB328kCGImageAlphaNoneSkipFirst
ARGB_32RGB328kCGImageAlphaPremultipliedFirst
RGBX_32RGB328kCGImageAlphaNoneSkipLast
RGBA_32RGB328kCGImageAlphaPremultipliedLast

Quartz does not support the following formats in a bitmap context:

  • 1-bit grayscale
  • 24-bit RGB
  • CMYK (any depth)

CGImageAlphaInfo constants:
kCGImageAlphaNone0
kCGImageAlphaPremultipliedLast1For example, premultiplied RGBA
kCGImageAlphaPremultipliedFirst2For example, premultiplied ARGB
kCGImageAlphaLast3For example, non-premultiplied RGBA
kCGImageAlphaFirst4For example, non-premultiplied ARGB
kCGImageAlphaNoneSkipLast5Equivalent to kCGImageAlphaNone.
kCGImageAlphaNoneSkipFirst6

The items on this page are in the following plugins: MBS MacCG Plugin.


The biggest plugin in space...