我正在使用苹果制造的AVCam作为我定制的相机视图。老实说,如果您第一次看到类AVCamViewController中发生的事情,那么了解它并不简单。
现在我感兴趣的是他们是如何设置拍摄到的图像框架的。我试图找到一些著名的策划人或诸如此类的东西,但我没有找到。
我在谷歌搜索并在这里找到答案,AVCam不在全屏
但当我实现该解决方案时,我只是意识到它只是制作了与我的视图大小相同的实时摄像头预览层,但是当应用程序在图片库中保存图像时,- (IBAction)snapStillImage:(id)sender在图片库中的图像仍然是左、右两条条纹。
我的问题是如何删除这些条纹,或者在源代码中的哪一行苹果设置了这些东西?
此外,作为附加的子问题,我如何设置类型创建只是照片,因为应用程序要求我“麦克风设置”,我不需要它只需要做一张照片,就这样。
这段来自苹果源的代码将图像保存到照片库中。
- (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];
}
}];
});
}发布于 2014-09-06 14:54:11
您正在设置会话预置吗?
您可以在AVCaptureSessionPresetPhoto中使用会话预置设置的会话。
对于另一个子问题:您只需要添加AVCaptureStillImageOutput输出。
如何设置会话预置?
[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];
}
});
}发布于 2014-09-05 12:34:33
为了保持高宽比,需要使用黑色字段,如果要避免这样做,您应该更改AVCaptureVideoPreviewLayer中的AVCaptureVideoPreviewLayer,或者显示捕获图像的UIImageView的contentMode。
这是一种预期的行为,不要理解你的担忧。
https://stackoverflow.com/questions/25685179
复制相似问题