Reputation: 499
I am using AVCaptureSession
for taking pictures. Here is my code:
AVCaptureSession * newSession = [[AVCaptureSession alloc] init];
// Configure our capturesession
newSession.sessionPreset = AVCaptureSessionPresetMedium;
I Got image with size 360*480. But here is my problem, I want image With Exactly the size 280*200. I am not interested with cropping the image. Any way to set image Size taken by AVCaptureSession
? Thanks in advance..
Upvotes: 1
Views: 4876
Reputation: 3629
With AVCapturePresets you have an explicit size that video or photos will be captured at. Once you take your photo, you can manipulate (crop, resize) to fit your desired size, but you cannot set a predetermined capture size.
There are the acceptable presets:
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;
This method is something I use that should help you scale to your desired size:
-(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Initializing session & setting up preset:
// create a capture session
if(session == nil){
session = [[AVCaptureSession alloc] init];
}
if ([session canSetSessionPreset:AVCaptureSessionPreset320x240]) {
session.sessionPreset = AVCaptureSessionPreset320x240;
}
else {
NSLog(@"Cannot set session preset");
}
Upvotes: 3