gpt4 book ai didi

objective-c - iPad 捕获 16 :9 photos

转载 作者:行者123 更新时间:2023-11-29 13:23:06 24 4
gpt4 key购买 nike

我正在 iOS 上构建一个原型(prototype)应用程序,并且我正在拆解一些 Apple 示例代码来完成它(我知道,如履薄冰——这段代码使用 goto 语句 :\)。我正在使用 Session 520 中的 AVCam 项目 - Camera Capture 的新增功能。我不需要视频捕捉功能,只需要静态照片。

设备输入和输出设置如下:

    // Init the device inputs
AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:nil];
AVCaptureDeviceInput *newAudioInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self audioDevice] error:nil];


// Setup the still image file output
AVCaptureStillImageOutput *newStillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = @{AVVideoCodecKey: AVVideoCodecJPEG};
[newStillImageOutput setOutputSettings:outputSettings];


// Create session (use default AVCaptureSessionPresetHigh)
AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init];


// Add inputs and output to the capture session
if ([newCaptureSession canAddInput:newVideoInput]) {
[newCaptureSession addInput:newVideoInput];
}
if ([newCaptureSession canAddInput:newAudioInput]) {
[newCaptureSession addInput:newAudioInput];
}
if ([newCaptureSession canAddOutput:newStillImageOutput]) {
[newCaptureSession addOutput:newStillImageOutput];
}

[self setStillImageOutput:newStillImageOutput];
[self setVideoInput:newVideoInput];
[self setAudioInput:newAudioInput];
[self setSession:newCaptureSession];

下面是我点击快门按钮时调用的方法:

- (void) captureStillImage
{
AVCaptureConnection *stillImageConnection = [[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo];
if ([stillImageConnection isVideoOrientationSupported])
[stillImageConnection setVideoOrientation:orientation];

[[self stillImageOutput]
captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) {
if (error)
{
if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)])
{
[[self delegate] captureManager:self didFailWithError:error];
}
}
};

if (imageDataSampleBuffer != NULL)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

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

if ([self.delegate respondsToSelector:@selector(captureManagerCapturedImage:)])
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate captureManagerCapturedImage:image];
});
}

[library writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation)[image imageOrientation]
completionBlock:completionBlock];

}
else
{
completionBlock(nil, error);
}

if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)])
{
[[self delegate] captureManagerStillImageCaptured:self];
}
}];
}

此代码成功捕获图像并将其保存到库中。然而,在我处理它的某个时候,它从捕获 5 兆像素的 4:3 图像变为捕获 1920x1080 16:9 图像。我找不到指定宽高比的任何地方,而且我没有更改任何与相机配置、捕获 session 或捕获连接相关的代码。为什么我的相机开始拍摄 16:9 的照片?

更新:我刚刚重新运行了 Apple 的原始示例代码,它似乎也在保存直接从视频中捕获的 16:9 图像。很可能我之前疯了,或者我用 Camera.app 试拍了一张并正在看它。所以我真正的问题是,我如何在拍摄时在屏幕上显示来自相机的实时画面,并拍摄一张全分辨率照片。我不能使用 UIImagePickerController,因为我需要能够在实时摄像头画面上叠加内容。

更新 2: 我能够通过丢弃我正在使用的 AVCapture 代码来解决这个问题。结果是 UIImagePickerController 做了我需要的。我没有意识到您可以叠加自定义控件 - 我以为它会占据整个屏幕,直到您拍完照片为止。

最佳答案

如果您从视频源中捕捉帧,您最终会得到 16:9 的分辨率。从视频源捕获帧和拍照是两回事。

关于objective-c - iPad 捕获 16 :9 photos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13863743/

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