<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vImage_Buffer/preferredAlignmentAndRowBytes(width:height:bitsPerPixel:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:So13vImage_BufferV10AccelerateE29preferredAlignmentAndRowBytes5width6height12bitsPerPixelSi9alignment_Si03rowH0tSi_Sis6UInt32VtKFZ"
  },
  "title" : "preferredAlignmentAndRowBytes(width:height:bitsPerPixel:)"
}
-->

# preferredAlignmentAndRowBytes(width:height:bitsPerPixel:)

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

```
static func preferredAlignmentAndRowBytes(width: Int, height: Int, bitsPerPixel: UInt32) throws -> (alignment: Int, rowBytes: Int)
```

## Parameters

`width`

The width of the image, in pixels.

`height`

The height of the image, in pixels.

`bitsPerPixel`

The number of bits in a single pixel.

## Return Value

A tuple that contains the alignment and row bytes.

## Discussion

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)
```

---

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)