avcapturesession - iphone camera show focus rectangle -


i cloning apple's camera app using avcapturesession based on apple's appcam app sample. problem cannot see focus rectangle in video preview screen. used following code setting focus, still focus rectangle not shown.

  avcapturedevice *device = [[self videoinput] device]; if ([device isfocusmodesupported:focusmode] && [device focusmode] != focusmode) {     nserror *error;        printf(" setfocusmode    \n");     if ([device lockforconfiguration:&error]) {         [device setfocusmode:focusmode];         [device unlockforconfiguration];     } else {         id delegate = [self delegate];         if ([delegate respondstoselector:@selector(acquiringdevicelockfailedwitherror:)]) {             [delegate acquiringdevicelockfailedwitherror:error];         }     }     } 

when use uiimagepickercontroller, auto focus, tap focus supported default, , can see focus rectangle. there no way show focus rectangle in video preview layer using avcapturesession?

the focus animation complete custom animation have create own. having exact same problem you: want show rectangle feedback user after tapped preview layer.

the first thing want implementing tap-to-focus, initiate preview layer:

uitapgesturerecognizer *tapgr = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(taptofocus:)]; [tapgr setnumberoftapsrequired:1]; [tapgr setnumberoftouchesrequired:1]; [self.capturevideopreviewview addgesturerecognizer:tapgr]; 

now implement tap-to-focus method itself:

-(void)taptofocus:(uitapgesturerecognizer *)singletap{     cgpoint touchpoint = [singletap locationinview:self.capturevideopreviewview];     cgpoint convertedpoint = [self.capturevideopreviewlayer capturedevicepointofinterestforpoint:touchpoint];     avcapturedevice *currentdevice = currentinput.device;      if([currentdevice isfocuspointofinterestsupported] && [currentdevice isfocusmodesupported:avcapturefocusmodeautofocus]){         nserror *error = nil;         [currentdevice lockforconfiguration:&error];         if(!error){             [currentdevice setfocuspointofinterest:convertedpoint];             [currentdevice setfocusmode:avcapturefocusmodeautofocus];             [currentdevice unlockforconfiguration];         }         } } 

the last thing, haven't implemented myself yet, add focusing animation preview layer or rather view controller holding preview layer. believe done in taptofocus:. there have touch point. add animated image view or other view has touch position center. after animation has finished, remove image view.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -