<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vImage/PixelBuffer",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate6vImageO11PixelBufferV"
  },
  "title" : "vImage.PixelBuffer"
}
-->

# vImage.PixelBuffer

An image buffer that stores an image’s pixel data, dimensions, bit depth, and number of channels.

```
struct PixelBuffer<Format> where Format : PixelFormat
```

## Overview

Use a [`vImage.PixelBuffer`](/documentation/Accelerate/vImage/PixelBuffer) to represent an image from a <doc://com.apple.documentation/documentation/CoreGraphics/CGImage> instance, a <doc://com.apple.documentation/documentation/CoreVideo/CVPixelBuffer> structure, or a collection of raw pixel values. Pixel buffers are typed by their bits per channel and number of channels. For example, [`vImage.Interleaved8x4`](/documentation/Accelerate/vImage/Interleaved8x4) indicates a 4-channel, 8-bit-per-channel pixel buffer that contains image data such as RGBA or CMYK.

Pixel buffers expose methods that are available for the buffer’s pixel format. For example, the fast box convolution functions are only available for one- and four-channel 8-bit per channel buffers:

```swift
 let src = vImage.PixelBuffer<vImage.Interleaved8x4>(cgImage: cgImage,
                                                     cgImageFormat: &cgImageFormat)
 let dest = vImage.PixelBuffer<vImage.Interleaved8x4>(src.size)

 src.boxConvolve(kernelSize: vImage.Size(width: 64, height: 64),
                 edgeMode: .truncateKernel,
                 destination: dest)
```

Typed pixel buffers provide a simple API to convert between pixel formats. For example, the following code converts 8-bit unsigned integer pixels to 32-bit floating point pixels:

```swift
 let src = vImage.PixelBuffer<vImage.Interleaved8x4>(cgImage: cgImage,
                                                     cgImageFormat: &cgImageFormat)
 let dest = vImage.PixelBuffer<vImage.InterleavedFx4>(size: src.size)

 src.convert(to: dest)
```

vImage pixel buffers manage their memory, therefore, you don’t need to call <doc://com.apple.documentation/documentation/Swift/UnsafeMutableRawPointer/deallocate()> when you’re finished with the buffer.

## Topics

### Pixel buffer essentials

  <doc://com.apple.accelerate/documentation/Accelerate/creating-vimage-pixel-buffers>

  <doc://com.apple.accelerate/documentation/Accelerate/pixel-formats>

  <doc://com.apple.accelerate/documentation/Accelerate/working-with-underlying-data>

### Inspecting a pixel buffer

[`width`](/documentation/Accelerate/vImage/PixelBuffer/width)

The width of the pixel buffer.

[`height`](/documentation/Accelerate/vImage/PixelBuffer/height)

The height of the pixel buffer.

[`size`](/documentation/Accelerate/vImage/PixelBuffer/size)

The size of the pixel buffer.

[`channelCount`](/documentation/Accelerate/vImage/PixelBuffer/channelCount)

Returns the number of channels.

[`rowStride`](/documentation/Accelerate/vImage/PixelBuffer/rowStride)

The width, in pixels, of the underlying memory, including any additional row byte padding.

[`byteCountPerPixel`](/documentation/Accelerate/vImage/PixelBuffer/byteCountPerPixel)

Returns the number of bytes per pixel.

[`count`](/documentation/Accelerate/vImage/PixelBuffer/count)

The total number of pixels multiplied by the number of channels in the buffer, including any row padding.

[`array`](/documentation/Accelerate/vImage/PixelBuffer/array)

An array of `width * height * channelCount` values that’s a copy of the buffer’s visible contents.

### Pixel buffer methods

[`copy(to:)`](/documentation/Accelerate/vImage/PixelBuffer/copy(to:))

Copies the contents of the pixel buffer to another pixel buffer.

[`copy(to:cvImageFormat:cgImageFormat:)`](/documentation/Accelerate/vImage/PixelBuffer/copy(to:cvImageFormat:cgImageFormat:))

Copies the contents of a pixel buffer to a Core Video pixel buffer.

[`makeCGImage(cgImageFormat:)`](/documentation/Accelerate/vImage/PixelBuffer/makeCGImage(cgImageFormat:))

Returns a Core Graphics image from the pixel buffer’s contents.

[`withCVPixelBuffer(readOnly:body:)`](/documentation/Accelerate/vImage/PixelBuffer/withCVPixelBuffer(readOnly:body:))

Calls the given closure with a locked 32-bit BGRA Core Video Pixel Buffer.

### Pixel buffer operations

  <doc://com.apple.accelerate/documentation/Accelerate/applying-geometric-operations-to-pixel-buffers>

  <doc://com.apple.accelerate/documentation/Accelerate/applying-color-transforms-to-pixel-buffers>

  <doc://com.apple.accelerate/documentation/Accelerate/blending-and-compositing-pixel-buffers>

  <doc://com.apple.accelerate/documentation/Accelerate/convolving-and-applying-morphology>

  <doc://com.apple.accelerate/documentation/Accelerate/thresholding-and-clipping-pixel-buffer-values>

  <doc://com.apple.accelerate/documentation/Accelerate/calculating-and-transforming-histograms>

  <doc://com.apple.accelerate/documentation/Accelerate/converting-pixel-buffers>

  <doc://com.apple.accelerate/documentation/Accelerate/interleaving-and-deinterleaving-pixel-buffers>

  <doc://com.apple.accelerate/documentation/Accelerate/cropping-and-working-with-regions-of-interest>

  <doc://com.apple.accelerate/documentation/Accelerate/applying-channel-operations>

  <doc://com.apple.accelerate/documentation/Accelerate/applying-arithmetic-operations>



---

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)