3
iOS에서 사진을 찍으려고합니다.captureStillImageAsynchronouslyFromConnection 메서드로 포커스하는 방법
나는 방법에서 이미지를 가져 와서 붙였습니다. captureStillImageAsynchronouslyFromConnection.
나는 그 방법을 구현하지만 작동하지만 내 문제는 이미지를 즉시 받아들이고 먼저 초점을 맞추기 위해 기다리지 않는다는 것입니다.
나는 정말로 대답을 찾으려고했지만 나는하지 않았다.
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];
그러나 불행하게도 촬영에 초점이 맞춰지지 않은 것입니다 :
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];
및 버튼
내가 가진 누르면 :는이 같은 미리보기 영상을 구현합니다.
나를 도와 줄 수 있습니까?
마르코 당신은 조정의 초점 값을 관찰하고이 완료된 후 사진을 촬영하기 위해보고 싶지
누구든지이 문제를 해결하는 방법을 알고 있습니까? –
@Marco -이 문제에 도움을 받으셨습니까? – Patricia