camera - How to convert code AVFoundation objective c to Swift? -
camera - How to convert code AVFoundation objective c to Swift? -
i using avfoundation in swift take pictures can't convert func lines of code objective c swift. func code is:
- (void) capimage { //method capture image avcapturesession video feed avcaptureconnection *videoconnection = nil; (avcaptureconnection *connection in stillimageoutput.connections) { (avcaptureinputport *port in [connection inputports]) { if ([[port mediatype] isequal:avmediatypevideo] ) { videoconnection = connection; break; } } if (videoconnection) { break; } } nslog(@"about request capture from: %@", stillimageoutput); [stillimageoutput capturestillimageasynchronouslyfromconnection:videoconnection completionhandler: ^(cmsamplebufferref imagesamplebuffer, nserror *error) { if (imagesamplebuffer != null) { nsdata *imagedata = [avcapturestillimageoutput jpegstillimagensdatarepresentation:imagesamplebuffer]; [self processimage:[uiimage imagewithdata:imagedata]]; } }]; }
this line send me error anyobject[]does not conform protocol sequencfe..:
(avcaptureinputport *port in [connection inputports]) { in swift:
port:anyobject in connection.inputports { and don't know how convert line:
[stillimageoutput capturestillimageasynchronouslyfromconnection:videoconnection completionhandler: ^(cmsamplebufferref imagesamplebuffer, nserror *error) { can u help me convert swift? thanks!!
for (avcaptureinputport *port in [connection inputports]) { )
arrays of anyobject should cast arrays of actual type before interating, this:
for (port in connection.inputports avcaptureinputport[]) { } in terms of blocks closures, have syntax correct.
stillimageoutput.capturestillimageasynchronouslyfromconnection(videoconnection) { (imagesamplebuffer, error) in // line defines names inputs //... } note uses trailing closure syntax. read on docs more!
edit: in terms of initializers, this:
let imagedata = avcapturestillimageoutput.jpegstillimagensdatarepresentation(imagesamplebuffer) self.processimage(uiimage(data:imagedata)) camera avfoundation swift xcode6
Comments
Post a Comment