2

我正在使用苹果制造的AVCam作为我的自定义相机视图。AVCamViewController老实说,如果您第一次看到课堂上发生的事情,要了解课堂上发生的事情并不容易。

现在我很感兴趣他们如何设置捕获图像的框架。我试图找到一些成名者或类似的东西,但我没有找到。

我在谷歌搜索并在这里找到答案AVCam not in fullscreen

但是当我实现该解决方案时,我才意识到它只是制作了与我的视图大小相同的实时相机预览层,但是当应用程序- (IBAction)snapStillImage:(id)sender在图库中的方法中保存图像时,图像仍然是左右两条条纹。

我的问题是如何删除这些条纹或苹果在源代码中的哪一行设置了这些东西?

另外作为附加子问题,我如何设置类型只创建照片,因为该应用程序要求我“麦克风设置”,而我不需要它只需要制作照片就可以了。

来自苹果来源的这段代码会将图像保存到照片库中。

- (IBAction)snapStillImage:(id)sender
{
    dispatch_async([self sessionQueue], ^{
        // Update the orientation on the still image output video connection before capturing.
        [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];

        // Flash set to Auto for Still Capture
        [AVCamViewController setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];

        // Capture a still image.
        [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

            if (imageDataSampleBuffer)
            {
                NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];

                UIImage *image = [[UIImage alloc] initWithData:imageData];

                UIImage *proccessingImage = [SAPAdjustImageHelper adjustImage:image];

                NSNumber *email_id = [SAPCoreDataEmailHelper currentEmailId];

                [SAPFileManagerHelper addImage:proccessingImage toFolderWithEmailId:email_id];
            }
        }];
    });
}
4

2 回答 2

4

您是否正在设置会话预设?

您可以将您的会话与在 中设置的会话预设一起使用AVCaptureSessionPresetPhoto

对于另一个子问题:您只需要添加AVCaptureStillImageOutput输出。

如何设置会话预设?

[session setSessionPreset:AVCaptureSessionPresetPhoto];

如何将会话配置为仅使用 StillImageOutput 拍照和?

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Create the AVCaptureSession
    AVCaptureSession *session = [[AVCaptureSession alloc] init];
    [self setSession:session];

    // Setup the preview view
    [[self previewView] setSession:session];

    // Setup the session Preset          
    [session setSessionPreset:AVCaptureSessionPresetPhoto];

    // Check for device authorization
    [self checkDeviceAuthorizationStatus];

    dispatch_queue_t sessionQueue = dispatch_queue_create("session queue", DISPATCH_QUEUE_SERIAL);
    [self setSessionQueue:sessionQueue];

    dispatch_async(sessionQueue, ^{
        //[self setBackgroundRecordingID:UIBackgroundTaskInvalid];

        NSError *error = nil;

        AVCaptureDevice *videoDevice = [AVCamViewController deviceWithMediaType:AVMediaTypeVideo preferringPosition:AVCaptureDevicePositionBack];
        AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];

        if (error)
        {
            NSLog(@"%@", error);
        }

        if ([session canAddInput:videoDeviceInput])
        {
            [session addInput:videoDeviceInput];
            [self setVideoDeviceInput:videoDeviceInput];

            dispatch_async(dispatch_get_main_queue(), ^{
                // Why are we dispatching this to the main queue?
                // Because AVCaptureVideoPreviewLayer is the backing layer for AVCamPreviewView and UIView can only be manipulated on main thread.
                // Note: As an exception to the above rule, it is not necessary to serialize video orientation changes on the AVCaptureVideoPreviewLayer’s connection with other session manipulation.

                [[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] setVideoOrientation:(AVCaptureVideoOrientation)[self interfaceOrientation]];
            });
        }

AVCaptureStillImageOutput *stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
        if ([session canAddOutput:stillImageOutput])
        {
            [stillImageOutput setOutputSettings:@{AVVideoCodecKey : AVVideoCodecJPEG}];
            [session addOutput:stillImageOutput];
            [self setStillImageOutput:stillImageOutput];
        }
    });
}
于 2014-09-06T14:54:11.477 回答
0

需要黑色字段来保持纵横比,如果要避免它们,您应该更改显示捕获图像videoGravityAVCaptureVideoPreviewLayer或 中的contentMode。 这是预期的行为,不了解您的担忧。UIImageView

于 2014-09-05T12:34:33.513 回答