ios - Capture still image from AVCaptureSession in Swift -
i have avcapturesession
displays live video in uiview, , want save frame of video stream uiimage. i've been dissecting code maintain seeing around internet, i'm having problem first line:
if allow stilloutput = self.stillimageoutput { // found avcaptureconnection , capture still image it. }
this gives me error 'camera' not have fellow member named 'stillimageoutput'. code depends on beingness able video connection output.
i can post total code block if that'd helpful. thanks!
once have stillimageoutput
can utilize next methods capture image
stillimageoutput.outputsettings = [avvideocodeckey:avvideocodecjpeg] if capturesession.canaddoutput(stillimageoutput) { capturesession.addoutput(stillimageoutput) } // had add together timer otherwise quality messed in ipad var timer = nstimer.scheduledtimerwithtimeinterval(0.4, target: self, selector: selector("getimage"), userinfo: nil, repeats: false)
than function image
func getimage() { if allow videoconnection = stillimageoutput.connectionwithmediatype(avmediatypevideo) { stillimageoutput.capturestillimageasynchronouslyfromconnection(videoconnection) { (imagedatasamplebuffer, error) -> void in allow imagedata = avcapturestillimageoutput.jpegstillimagensdatarepresentation(imagedatasamplebuffer) // utilize image or store album // uiimagewritetosavedphotosalbum(uiimage(data: imagedata), nil, nil, nil) self.stopsession() } } }
and stop session , remove preview layer
func stopsession(){ self.capturesession.stoprunning() self.previewlayer?.removefromsuperlayer() }
ios swift
No comments:
Post a Comment