gpt4 book ai didi

ios - AVCam 保存全屏捕获的图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:27:42 25 4
gpt4 key购买 nike

我正在使用 AVCam苹果为我的自定义相机 View 制作的。老实说,如果您是第一次看到 AVCamViewController 类,那么理解类中发生的事情并不容易。

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

我在 Google 中搜索并在此处找到答案 AVCam not in fullscreen

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

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

还有一个额外的子问题,我如何设置类型只创建照片,因为应用程序要求我“麦克风设置”,我不需要它,只需要拍一张照片就可以了。

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

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

最佳答案

您是否正在设置 session 预设?

您可以将您的 session 与 AVCaptureSessionPresetPhoto 中设置的 session 预设一起使用。

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

如何设置session Preset?

[session setSessionPreset:AVCaptureSessionPresetPhoto];

如何配置session只使用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];
}
});
}

关于ios - AVCam 保存全屏捕获的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25685179/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com