<!--
{
  "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/clip(to:destination:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate6vImageO11PixelBufferVA2A06StaticC6FormatRzSf13ComponentTypeRtzrlE4clip2to11destinationySNySfG_AEy_xGtF"
  },
  "title" : "clip(to:destination:)"
}
-->

# clip(to:destination:)

Clips the values of a 32-bit pixel buffer to the specified bounds.

```
func clip(to bounds: ClosedRange<Float>, destination: vImage.PixelBuffer<Format>)
```

## Parameters

`bounds`

The clipping range.

`destination`

The destination pixel buffer.

## Discussion

Use this function to set all pixel values outside of the clipping range to the lower and upper bounds. For example, the following code clips pixel values to the range `0.25 ... 0.75`.

The function clips the source values `0.0` and `0.2` to `0.25`, and the source values `0.8` and `1.0` to `0.75`.

```swift
let buffer = vImage.PixelBuffer<vImage.PlanarF>(
    pixelValues: [0.0, 0.2, 0.4, 0.6, 0.8, 1.0],
    size: vImage.Size(width: 6,
                      height: 1))

buffer.clip(to: 0.25 ... 0.75,
            destination: buffer)

// Prints "[0.25, 0.25, 0.4, 0.6, 0.75, 0.75]".
print(buffer.array)
```

---

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)