Initializes a vImage buffer of a specified size.


func vImageBuffer_Init(_ buf: UnsafeMutablePointer<vImage_Buffer>, _ height: vImagePixelCount, _ width: vImagePixelCount, _ pixelBits: UInt32, _ flags: vImage_Flags) -> vImage_Error



A valid empty vImage_Buffer structure. On return, all fields are initialized.


The height of the image.


The width of the image.


The number of bits in a pixel of image data. If pixelBits isn't divisible by 8, vImage pads the scanline out to a multiple of a byte so that two scanlines can't share the same byte, and all scanlines start at the beginning of a byte.


The options to use when performing this operation. The following flags are supported:


Default behavior.


On return, buf->data is initialized to NULL. A preferred alignment suitable for use with posix_memalign(_:_:_:) is returned and buf->rowBytes is set to the preferred rowBytes. A negative value returned by the function represents an error code, not a size.


Prints a debug message if the operation fails.

Return Value

kvImageNoError; otherwise, one of the error codes described in Data Types and Constants.


This function is a convenience method to help you initialize a vImage_Buffer structure with a buffer sized and is aligned for best performance. It initializes the height, width, and rowBytes fields, and allocates the pixel storage for you. You're responsible for releasing the memory pointed to by buf->data back to the system when you're done with it, using free().

See Also

Initializing vImage Buffers

struct vImage_Buffer

The basic data structure used by vImage functions for passing image data.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software