gpt4 book ai didi

ios - 带有 Split View的自定义相机 View

转载 作者:行者123 更新时间:2023-11-29 12:27:43 26 4
gpt4 key购买 nike

我创建了许多单帧到多帧的布局。我们应该在选择相机出现后选择任何布局来拍照,帧将以 Split View显示。如果我们选择一个有 3 个帧的布局,我们正在拍摄选择第二帧,不应该应用第一和第三个相机。我也看到了 AVCam 示例代码,但没有得到正确的代码。如何为自定义相机使用分割图像。希望有人帮忙。

最佳答案

您好,我通过 AVFoundation 框架得到了答案,我搜索了很多网站以及 AVCam apple 示例。通过采用不同的 View 和 ImageView ,我了解了在哪里使用相机预览

 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 = [SecondViewController 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(), ^{
[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] setVideoOrientation:(AVCaptureVideoOrientation)[self interfaceOrientation]];
});
}

AVCaptureDevice *audioDevice = [[AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio] firstObject];
AVCaptureDeviceInput *audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error];

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

if ([session canAddInput:audioDeviceInput])
{
[session addInput:audioDeviceInput];
}

AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
if ([session canAddOutput:movieFileOutput])
{
[session addOutput:movieFileOutput];
AVCaptureConnection *connection = [movieFileOutput connectionWithMediaType:AVMediaTypeVideo];
if ([connection isVideoStabilizationSupported])
[connection setEnablesVideoStabilizationWhenAvailable:YES];
[self setMovieFileOutput:movieFileOutput];
}

AVCaptureStillImageOutput *stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
if ([session canAddOutput:stillImageOutput])
{
[stillImageOutput setOutputSettings:@{AVVideoCodecKey : AVVideoCodecJPEG}];
[session addOutput:stillImageOutput];
[self setStillImageOutput:stillImageOutput];
}
});

[[自 session ] 开始运行];

通过使用这段代码和一些重要的方法,如 deviceWithMediaType、setFlashMode,我得到了我的解决方案

关于ios - 带有 Split View的自定义相机 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28605061/

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