Created
October 13, 2017 08:32
-
-
Save NikhilManapure/259e4d7a5bb53636ad378bfb4eec9062 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if let outputs = camera.captureSession.outputs { | |
for output in outputs { | |
if let output = output as? AVCaptureStillImageOutput { | |
if let videoConnection = output.connection(withMediaType: AVMediaTypeVideo) { | |
output.captureStillImageAsynchronously(from: videoConnection, completionHandler: { (imageDataSampleBuffer, error) in | |
if let imageDataSampleBuffer = imageDataSampleBuffer { | |
let data: Data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer) | |
let rawMetadata = CMCopyDictionaryOfAttachments(nil, imageDataSampleBuffer, CMAttachmentMode(kCMAttachmentMode_ShouldPropagate)) | |
let metadata = CFDictionaryCreateMutableCopy(nil, 0, rawMetadata) as NSMutableDictionary | |
let exifData = metadata.value(forKey: kCGImagePropertyExifDictionary as String) as? NSMutableDictionary | |
exifData?.setValue(Date().toString(withFormat: "yyyy:MM:dd HH:mm:ss"), forKey: kCGImagePropertyExifDateTimeDigitized as String) | |
metadata.setValue(exifData, forKey: kCGImagePropertyExifDictionary as String) | |
metadata.setValue(1, forKey: kCGImagePropertyOrientation as String) | |
metadata.setValue(self.camera.inputCamera.iso, forKey: kCGImagePropertyExifISOSpeed as String) | |
if let image = UIImage(data: data) { | |
// Use Image | |
} else { | |
// Error | |
} | |
} else if let error = error { | |
onError(error) | |
} else { | |
onError(NSError(domain: "Something is unusually wrong", code: 0, userInfo: nil)) | |
} | |
}) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment