ios - Swift 3/4 - Camera for iOS10 and older -
i'm trying implement camera in app. seems work on ios 11 not on previous version ...
xcode tells me part (the function photooutput()) not ios 10 , older version.
extension uploadviewcontroller: avcapturephotocapturedelegate { @available(ios 11.0, *) func photooutput(_ output: avcapturephotooutput, didfinishprocessingphoto photo: avcapturephoto, error: error?) { if let imagedata = photo.filedatarepresentation() { image = uiimage(data: imagedata) let photosecondvc = self.storyboard?.instantiateviewcontroller(withidentifier: "uploadsecondvc") as! uploadsecondviewcontroller photosecondvc.imagedata = image! self.navigationcontroller?.pushviewcontroller(photosecondvc, animated: false) self.dismiss(animated: true, completion: nil) } } }
and action taking picture:
@ibaction func takephotoaction(_ sender: any) { let settings = avcapturephotosettings() photooutput?.capturephoto(with: settings, delegate: self) }
i don't know how translate function previous versions of ios ...
i found one:
func photooutput(_ captureoutput: avcapturephotooutput, didfinishprocessingphoto photosamplebuffer: cmsamplebuffer?, previewphoto previewphotosamplebuffer: cmsamplebuffer?, resolvedsettings: avcaptureresolvedphotosettings, bracketsettings: avcapturebracketedstillimagesettings?, error: error?)
but there a lot of parameters , it's not working well, i'm not sure it's 1 :/
could me please ?
what tried:
@ibaction func takephotoaction(_ sender: any) { let settings = avcapturephotosettings() let previewpixeltype = settings.availablepreviewphotopixelformattypes.first! let previewformat = [kcvpixelbufferpixelformattypekey string: previewpixeltype, kcvpixelbufferwidthkey string: 160, kcvpixelbufferheightkey string: 160] settings.previewphotoformat = previewformat photooutput?.capturephoto(with: settings, delegate: self) } func photooutput(_ captureoutput: avcapturephotooutput, didfinishprocessingphoto photosamplebuffer: cmsamplebuffer?, previewphoto previewphotosamplebuffer: cmsamplebuffer?, resolvedsettings: avcaptureresolvedphotosettings, bracketsettings: avcapturebracketedstillimagesettings?, error: error?) { if let error = error { print("error occure : \(error.localizeddescription)") } if let samplebuffer = photosamplebuffer, let previewbuffer = previewphotosamplebuffer, let dataimage = avcapturephotooutput.jpegphotodatarepresentation(forjpegsamplebuffer: samplebuffer, previewphotosamplebuffer: previewbuffer) { print(uiimage(data: dataimage)?.size any) let dataprovider = cgdataprovider(data: dataimage cfdata) let cgimageref: cgimage! = cgimage(jpegdataprovidersource: dataprovider!, decode: nil, shouldinterpolate: true, intent: .defaultintent) var orientation = uiimageorientation(rawvalue: 0) if isfront { orientation = uiimageorientation.leftmirrored } else { orientation = uiimageorientation.right } let image = uiimage(cgimage: cgimageref, scale: 1.0, orientation: orientation!) // var flippedimage = uiimage(cgimage: picture.cgimage!, scale: picture.scale, orientation: .leftmirrored) let timage = crop(image, withwidth: 100, andheight: 100) let photosecondvc = self.storyboard?.instantiateviewcontroller(withidentifier: "uploadsecondvc") as! uploadsecondviewcontroller photosecondvc.imagedata = timage! photosecondvc.isfront = isfront self.navigationcontroller?.pushviewcontroller(photosecondvc, animated: false) } else { print("some error here") } }
there huge delay when take picture (4 or 5 seconds ...) know why ?
wiki
Comments
Post a Comment