我正在iOS上构建一个原型应用程序,我正在使用苹果的一些示例代码来实现它(我知道,这段代码使用了goto语句)。我使用的AVCam项目从会话520 -什么是新的相机捕捉。我不需要视频捕捉功能,只需要照片。
设备输入和输出设置如下:
// 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];
}
}];
}此代码成功捕获图像并将其保存到库中。然而,在我工作的某个时候,它从捕捉500万像素的4:3图像转变为捕捉1920x1080 16:9的图像。我在任何地方都找不到指定高宽比的地方,也没有更改任何与相机配置、捕获会话或捕获连接相关的代码。为什么我的相机开始拍16:9的照片?
更新:I只是重新运行苹果的原始示例代码,它似乎也保存了直接从视频中捕获的16:9图像。很有可能我以前是疯了,或者我用Camera.app做了一次测试,并正在观察这个问题。所以我真正的问题是,当我拍摄的时候,如何在屏幕上显示摄像头的实时反馈,并拍摄一张全分辨率的照片。我不能使用UIImagePickerController,因为我需要能够在实时摄像头上覆盖东西。
更新2:我可以通过丢弃正在使用的AVCapture代码来解决这个问题。事实证明,UIImagePickerController做了我需要的事情。我不知道你可以覆盖自定义控件-我以为它接管了整个屏幕,直到你完成了一张照片。
发布于 2012-12-13 16:25:56
如果你从视频源捕获帧,你将得到16:9的分辨率。从视频源捕获帧和拍照是不同的事情。
https://stackoverflow.com/questions/13863743
复制相似问题