priore

Convert AVCaptureStillImageOutput to UIImage

Jul 7th, 2017
209
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // Convert AVCaptureStillImageOutput to UIImage without lose resolution
  2.     func imageFromSampleBuffer(sampleBuffer : CMSampleBuffer) -> UIImage
  3.     {
  4.         // convert UIImage without lose quality
  5.         let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
  6.         let ciImage = CIImage.init(cvPixelBuffer: pixelBuffer!)
  7.        
  8.         let context = CIContext.init()
  9.         let width = CVPixelBufferGetWidth(pixelBuffer!)
  10.         let height = CVPixelBufferGetHeight(pixelBuffer!)
  11.         let cgImage = context.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: width, height: height))
  12.            
  13.         let image = UIImage.init(cgImage: cgImage!);
  14.         return (image)
  15.     }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×