AVCam保存全屏捕获的图像 [英] AVCam save full screen captured image

查看:176
本文介绍了AVCam保存全屏捕获的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用苹果公司制造的 AVCam 用于我的自定义相机视图.老实说,如果您第一次看到它,要了解AVCamViewController类中发生的事情并不是简单的事情.

I am using AVCam made by apple for my custom camera view. Honestly it is not to simple to understand what's going on in the class AVCamViewController if you see it at first time.

现在我很感兴趣他们如何设置捕获图像的帧.我试图找到一些名利二传手或类似的东西,但我还没有找到.

Right now I am interested how they set frame of captured image. I tried to found where some fames setters or something like this, but I have not found any.

我在Google中进行了搜索,并在 AVCam不在全屏模式中找到答案

I searched in Google and found answer here AVCam not in fullscreen

但是当我实施该解决方案时,我才意识到它只是使实时摄像机预览层具有与我的视图相同的大小,但是当应用程序在库中的方法- (IBAction)snapStillImage:(id)sender中保存图像时,图像仍然在左侧有2条条纹没错.

But when I implemented that solution I just realised that it just made live camera preview layer with the same size as my view, but when app saves image in the method - (IBAction)snapStillImage:(id)sender in the gallery images still was with 2 stripes from left and right.

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

My question is how can I remove this stripes or in which line in source code apple set this stuff?

还有其他子问题,我该如何设置类型,仅创建照片,因为该应用会要求我提供麦克风设置",而我不需要它就只需要制作照片就可以了.

Also as additional sub-question how can I set type create just photo, because the app requests me "Microphone settings" and I don't need it just need make a photo and that's it.

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

This code from apple sources will save image to the photo library.

- (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];
            }
        }];
    });
}

推荐答案

您是否设置了会话预设?

Are you setting the session preset?

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

You can use your session with the session preset set in AVCaptureSessionPresetPhoto.

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

For the another subquestion: You need to add only the AVCaptureStillImageOutput output.

如何设置会话预设?

[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];
        }
    });
}

这篇关于AVCam保存全屏捕获的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆