如何使用Avcapture设置帧大小

我正在使用AVCaptureSession拍照。 这是我的代码:

 AVCaptureSession * newSession = [[AVCaptureSession alloc] init]; // Configure our capturesession newSession.sessionPreset = AVCaptureSessionPresetMedium; 

我得到了大小为360 * 480的图像。 但这里是我的问题,我想要的图像与280 * 200的大小。 我对裁剪图像不感兴趣。 任何方式来设置AVCaptureSession图像大小? 提前致谢..

使用AVCapturePresets,您将有一个明确的大小,video或照片将被捕获。 一旦拍摄了照片,您可以操作(裁剪,resize)以适合您所需的尺寸,但是无法设置预定的拍摄尺寸。

有可接受的预设:

 NSString *const AVCaptureSessionPresetPhoto; NSString *const AVCaptureSessionPresetHigh; NSString *const AVCaptureSessionPresetMedium; NSString *const AVCaptureSessionPresetLow; NSString *const AVCaptureSessionPreset320x240; NSString *const AVCaptureSessionPreset352x288; NSString *const AVCaptureSessionPreset640x480; NSString *const AVCaptureSessionPreset960x540; NSString *const AVCaptureSessionPreset1280x720; 

来源: https : //developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVCaptureSession_Class/Reference/Reference.html

这种方法是我使用的,应该可以帮助你缩放到你想要的尺寸:

 -(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize; { UIGraphicsBeginImageContext( newSize ); [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } 

初始化会话和设置预设:

 // create a capture session if(session == nil){ session = [[AVCaptureSession alloc] init]; } if ([session canSetSessionPreset:AVCaptureSessionPreset320x240]) { session.sessionPreset = AVCaptureSessionPreset320x240; } else { NSLog(@"Cannot set session preset"); }