<!--
{
  "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/init(data:width:height:byteCountPerRow:pixelFormat:)-zwzz",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate6vImageO11PixelBufferVA2A011SinglePlaneC6FormatRzrlE4data5width6height15byteCountPerRow05pixelG0AEy_xGSv_S3ixmtcfc"
  },
  "title" : "init(data:width:height:byteCountPerRow:pixelFormat:)"
}
-->

# init(data:width:height:byteCountPerRow:pixelFormat:)

Returns a new buffer that references existing data.

```
init(data: UnsafeMutableRawPointer, width: Int, height: Int, byteCountPerRow: Int, pixelFormat: Format.Type)
```

## Parameters

`data`

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

`width`

The width, in pixels, of the pixel buffer.

`height`

The height, in pixels, of the pixel buffer.

`byteCountPerRow`

The number of bytes in a pixel row.

`pixelFormat`

The pixel format of the initialized buffer.

## Discussion

You can use this function to simplify interoperation with other libraries and frameworks. For example, the following code shows a function that permutes the channels of a <doc://com.apple.documentation/documentation/CoreGraphics/CGImage> instance. The function creates a pixel buffer that uses the storage a <doc://com.apple.documentation/documentation/CoreGraphics/CGDataProvider> instance’s <doc://com.apple.documentation/documentation/CoreGraphics/CGDataProvider/data> property provides. The <doc://com.apple.documentation/documentation/CoreGraphics/CGDataProvider/data> property is a copy of the image data, therefore, the code returns a new <doc://com.apple.documentation/documentation/CoreGraphics/CGImage> instance that it generates from the permuted pixel buffer.

```swift
static func permute(image: CGImage,
                    to permuteMap: (UInt8, UInt8, UInt8, UInt8)) -> CGImage? {
    
    let bitsPerPixel = image.bitsPerPixel
    let bitsPerComponent = image.bitsPerComponent

    guard bitsPerPixel == 32 && bitsPerComponent == 8,
          let format = vImage_CGImageFormat(cgImage: image),
          let pixelData = image.dataProvider?.data else {
        return nil
    }
    
    return withExtendedLifetime(pixelData) {
        let pixelBuffer = vImage.PixelBuffer(
            data: UnsafeMutableRawPointer(mutating: CFDataGetBytePtr($0)),
            width: image.width,
            height: image.height,
            byteCountPerRow: image.bytesPerRow,
            pixelFormat: vImage.Interleaved8x4.self)
        
        pixelBuffer.permuteChannels(to: permuteMap,
                                    destination: pixelBuffer)
        
        return pixelBuffer.makeCGImage(cgImageFormat: format)
    }
}
```

> Important:
> The pixel buffer is valid only for the lifetime of `data`.

---

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)