3

iOSで写真を撮ろうとしています。

メソッドcaptureStillImageAsynchronouslyFromConnectionから画像を取得しました。

私はその方法を実装して動作しますが、私の問題は、すぐに画像を取得し、最初に焦点を合わせるのを待たないことです。

私は本当に答えを見つけようとしましたが、見つけられませんでした。

次のようなプレビュー ビデオを実装しました。

session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetHigh;
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.frame = cameraImage.frame;
captureVideoPreviewLayer.bounds = cameraImage.bounds;
captureVideoPreviewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;
[cameraImage.layer addSublayer:captureVideoPreviewLayer];
 device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];


 NSError *error = nil;


if ([session canSetSessionPreset:AVCaptureSessionPreset1920x1080]) {
    session.sessionPreset = AVCaptureSessionPreset1920x1080;
}

[session addInput:input];
stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey,nil];
[stillImageOutput setOutputSettings:outputSettings];

[session addOutput:stillImageOutput];

[session startRunning];

ボタンを押すと、次のようになります。

AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections)
{
    for (AVCaptureInputPort *port in [connection inputPorts])
    {
        if ([[port mediaType] isEqual:AVMediaTypeVideo] )
        {
            videoConnection = connection;
            break;
        }
    }
    if (videoConnection) { break; }
}


[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
 {
     CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
     if (exifAttachments)
     {
     }
     else{}


     // TAKE IMAGE


    if ([device lockForConfiguration:&error]) {
        [device setFocusPointOfInterest:CGPointMake(0.5f, 0.f)];
        [device setExposurePointOfInterest:CGPointMake(0.5f, 0.f)];

        [device setFocusMode:AVCaptureFocusModeAutoFocus];
        [device unlockForConfiguration];
    }
    NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
     UIImage *image = [[UIImage alloc] initWithData:imageData];
     UIImage *rotatedImage = [[UIImage alloc]initWithCGImage:image.CGImage scale:1.0f orientation:UIImageOrientationDown];

     [session stopRunning];

しかし、残念ながら撮影した写真はピントが合っていません。

誰かが私を助けることができますか?

マルコ

4

1 に答える 1