crop(at:destination:)
Crops the pixel buffer to a rectangle that’s defined by an origin and the destination buffer’s dimensions.
Declaration
func crop(at origin: CGPoint, destination: vImage.PixelBuffer<Format>)Parameters
- origin:
A point that specifies the origin of the image to keep.
- destination:
The destination pixel buffer.
Discussion
For example, the following code populates a pixel buffer from the center 3 x 3 pixels of a 5 x 5 planar buffer:
let src = vImage.PixelBuffer<vImage.Planar8>(
pixelValues: [ 10, 11, 12, 13, 14,
20, 21, 22, 23, 24,
30, 31, 32, 33, 34,
40, 41, 42, 43, 44,
50, 51, 52, 53, 54 ],
size: vImage.Size(width: 5,
height: 5))
let dest = vImage.PixelBuffer<vImage.Planar8>(
size: vImage.Size(width: 3,
height: 3))
src.crop(at: CGPoint(x: 1, y: 1),
destination: dest)
// Prints:
// [ 21, 22, 23,
// 31, 32, 33,
// 41, 42, 43 ]
print(dest.array)