<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vImage_Buffer",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@S@vImage_Buffer"
  },
  "title" : "vImage_Buffer"
}
-->

# vImage_Buffer

An image buffer that stores an image’s pixel data, dimensions, and row stride.

```
struct vImage_Buffer
```

## Overview

The vImage buffer is the fundamental data structure that the vImage library uses to represent image data. To ensure the best performance, the vImage buffer initialization functions may add extra padding to each row. For example, the following code declares an 8-bit per pixel buffer that’s 10 pixels wide:

```swift
var buffer = vImage_Buffer()

vImageBuffer_Init(&buffer,
                  5,    // height
                  10,   // width
                  8,    // bits per pixel
                  vImage_Flags(kvImageNoFlags))
```

Although the code defines a buffer with 10 bytes per row, to maximize performance, [`vImageBuffer_Init(_:_:_:_:_:)`](/documentation/Accelerate/vImageBuffer_Init(_:_:_:_:_:)) initializes a buffer with 16 bytes per row:

![A diagram that shows the visible pixels and the padding of a vImage buffer.](images/com.apple.accelerate/media-4052499@2x.png)

If you provide your own buffer storage, call [`preferredAlignmentAndRowBytes(width:height:bitsPerPixel:)`](/documentation/Accelerate/vImage_Buffer/preferredAlignmentAndRowBytes(width:height:bitsPerPixel:)) to get the row stride that ensures your buffer achieves the best performance.

```swift
let width = 10
let height = 5

let alignmentAndRowBytes = try vImage_Buffer.preferredAlignmentAndRowBytes(
    width: width,
    height: height,
    bitsPerPixel: 8)

// Prints "16".
print(alignmentAndRowBytes.rowBytes)

let data = UnsafeMutableRawPointer.allocate(
    byteCount: alignmentAndRowBytes.rowBytes * height,
    alignment: alignmentAndRowBytes.alignment)

let buffer = vImage_Buffer(data: data,
                           height: vImagePixelCount(height),
                           width: vImagePixelCount(width),
                           rowBytes: alignmentAndRowBytes.rowBytes)
```

## Topics

### Creating an empty vImage buffer

[`init(width:height:bitsPerPixel:)`](/documentation/Accelerate/vImage_Buffer/init(width:height:bitsPerPixel:))

Creates a new buffer with the specified width, height, and bits per pixel.

[`init(size:bitsPerPixel:)`](/documentation/Accelerate/vImage_Buffer/init(size:bitsPerPixel:))

Creates a new buffer with the specified size and bits per pixel.

[`init()`](/documentation/Accelerate/vImage_Buffer/init())

Creates an empty vImage buffer.

### Creating a buffer that references existing data

[`init(data:height:width:rowBytes:)`](/documentation/Accelerate/vImage_Buffer/init(data:height:width:rowBytes:))

Creates a new buffer with the specified size that references existing data.

[`preferredAlignmentAndRowBytes(width:height:bitsPerPixel:)`](/documentation/Accelerate/vImage_Buffer/preferredAlignmentAndRowBytes(width:height:bitsPerPixel:))

Returns the preferred alignment and row bytes for a specified size and bits per pixel.

### Consuming and producing Core Graphics images

[`init(cgImage:flags:)`](/documentation/Accelerate/vImage_Buffer/init(cgImage:flags:))

Creates a new buffer with the contents of a Core Graphics image.

[`init(cgImage:format:flags:)`](/documentation/Accelerate/vImage_Buffer/init(cgImage:format:flags:))

Creates a new buffer with the contents of a Core Graphics image using the supplied image format.

[`createCGImage(format:flags:)`](/documentation/Accelerate/vImage_Buffer/createCGImage(format:flags:))

Creates a Core Graphics image from the vImage buffer.

### Inspecting a buffer’s properties

[`data`](/documentation/Accelerate/vImage_Buffer/data)

A pointer to the top-left pixel of the image.

[`height`](/documentation/Accelerate/vImage_Buffer/height)

The height of the image, in pixels.

[`width`](/documentation/Accelerate/vImage_Buffer/width)

The width of the image, in pixels.

[`size`](/documentation/Accelerate/vImage_Buffer/size)

The size of the image, in pixels.

[`rowBytes`](/documentation/Accelerate/vImage_Buffer/rowBytes)

The distance, in bytes, between the start of one pixel row and the next in an image, including any unused space between them.

### Copying a buffer’s contents

[`copy(destinationBuffer:pixelSize:flags:)`](/documentation/Accelerate/vImage_Buffer/copy(destinationBuffer:pixelSize:flags:))

Copies the contents of a vImage buffer to the specified destination buffer.

### Deallocating a buffer

[`free()`](/documentation/Accelerate/vImage_Buffer/free())

Frees the resources associated with the vImage buffer.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)