title: Resize a CVPixelBuffer
body: <p>I'm trying to resize a CVPixelBuffer to a size of 128x128. I'm working with one that is 750x750. I'm currently using the CVPixelBuffer to create a new CGImage, which I resize then convert back into a CVPixelBuffer. Here is my code:</p>
  
  <pre><code>func getImageFromSampleBuffer (buffer:CMSampleBuffer) -&gt; UIImage? {
      if let pixelBuffer = CMSampleBufferGetImageBuffer(buffer) {
          let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
          let context = CIContext()
          let imageRect = CGRect(x: 0, y: 0, width: 128, height: 128)
  
          if let image = context.createCGImage(ciImage, from: imageRect) {
              let t = CIImage(cgImage: image)
              let new = t.applying(transformation)
              context.render(new, to: pixelBuffer)
  
              return UIImage(cgImage: image, scale: UIScreen.main.scale, orientation: .right)
          }
  
      }
  
      return nil
  }
  </code></pre>
  
  <p>I've also tried scaling the CIImage then converting it:</p>
  
  <pre><code>let t = CIImage(cgImage: image)
  let transformation = CGAffineTransform(scaleX: 1, y: 2)
  let new = t.applying(transformation)
  context.render(new, to: pixelBuffer)
  </code></pre>
  
  <p>But that didn't work either.</p>
  
  <p>Any help is appreciated. Thanks!</p>