ios - Custom camera works, live preview does not -
i'm attempting build custom camera app.
tasks:
- shows live image preview.
- allows tap anywhere on screen capture image.
- displays resulting image above live image preview.
currently works except task 1. view contains live image preview remains it's background color (or remains transparent when no background color selected), though camera operational , image displayed when screen tapped. ideas? i've referred previous discussion , think i'm covering bases: avfoundation camera preview layer not working
what missing?
-(void)viewwillappear:(bool)animated{ session = [[avcapturesession alloc] init]; [session setsessionpreset:avcapturesessionpresetphoto]; avcapturedevice *inputdevice = [avcapturedevice defaultdevicewithmediatype:avmediatypevideo]; nserror *error; avcapturedeviceinput *deviceinput = [avcapturedeviceinput deviceinputwithdevice:inputdevice error:&error]; if ([session canaddinput:deviceinput]) { [session addinput:deviceinput]; } avcapturevideopreviewlayer *previewlayer = [[avcapturevideopreviewlayer alloc] initwithsession:session]; [previewlayer setvideogravity:avlayervideogravityresizeaspectfill]; calayer *rootlayer = [[self view] layer]; [rootlayer setmaskstobounds:yes]; cgrect frame = self.frameforcapture.frame; [previewlayer setframe:frame]; [rootlayer insertsublayer:previewlayer atindex:0]; stillimageoutput = [[avcapturestillimageoutput alloc] init]; nsdictionary *outputsettings = [[nsdictionary alloc] initwithobjectsandkeys:avvideocodecjpeg, avvideocodeckey, nil]; [stillimageoutput setoutputsettings:outputsettings]; [session addoutput:stillimageoutput]; [session startrunning]; //.... }
Comments
Post a Comment