3

iPhoneカメラの焦点を合わせるために以下のコードを使用しました。しかし、それは機能していません。このコードは、Apple の AVCam サンプル コードから取得しました。私は何か間違ったことをしていますか?iPhone がフォーカスを合わせたかどうかを検出する方法はありますか?

-(void) focusAtPoint:(CGPoint)point   
{
    AVCaptureDevice *device =  [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];;

    if (device != nil) {            
        if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {

            NSError *error;

            if ([device lockForConfiguration:&error]) {             
                [device setFocusPointOfInterest:point];             
                [device setFocusMode:AVCaptureFocusModeAutoFocus];              
                [device unlockForConfiguration];                
            } else {                
                NSLog(@"Error in Focus Mode");
            }        

        }
    }
}
4

1 に答える 1

7

のポイント[AVCaptureDevice setFocusPointOfInterest:]は、ビューのタッチ ポイントと同じではなく、0,0 と 1,1 の間のポイントです (ドキュメントを参照)。だからあなたはしなければなりません:

CGPoint point = [touch locationInView:self.cameraView];
point.x /= self.cameraView.frame.size.width;
point.y /= self.cameraView.frame.size.height;
[self focusAtPoint:point];
于 2012-05-04T13:55:30.637 に答える