使用 AVCapturePresets,您可以明确地捕捉视频或照片的大小。拍摄照片后,您可以操作(裁剪、调整大小)以适合您想要的尺寸,但您无法设置预定的拍摄尺寸。
有可接受的预设:
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");
}