5

I want to capture images with 5 MP resolution in an iOS device where maximum image sensor capture resolution is 8 MP.

The presets provided in Avfoundations AVCaptureSessionPresetPhoto gives - 3264x2448 - 8 MP resolution VCaptureSessionPresetHigh gives - 1920x1080 - 2 MP resolution

Is there any way/workaround for capturing 5MP directly, instead of capturing 8MP and then downscaling?

thar_bun
  • 820
  • 1
  • 5
  • 20

3 Answers3

2

iOS gives very limited output resolutions from Camera.

You mentioned correctly that largest size is 8MP and next preset goes down to 1080p or ~2MP. The expectation it seems is to downscale/crop the image as the application requires, however the SDK doesn't give a single API to get required resolution or output image.

Hope this helps.

poloolop
  • 144
  • 12
2

AVCaptureSessionPreset gives only constants resolutions (You can see API references). If you want to save image in custom resolution, you can find here Save image with custom resolution

Community
  • 1
  • 1
GMJigar
  • 496
  • 4
  • 14
  • Your solution is very helpful. It is useful to obtain UIImage from the screen at custom resolution. I am trying to capture image in YUV420SP format, is there any way i could capture YUV420 at custom resolution. – thar_bun Jan 31 '14 at 08:19
  • If I understopod properly, in the solution you have pointed we are resizing the UIImage using Core graphics APIs, to obtain custom resolution. Correct me if my understanding is wrong. – thar_bun Jan 31 '14 at 08:31
1

why don't you capture image with 8MP camera and then before saving image change its size w.r.t 5MP resolution using following method

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

call the above method in imagePickerDidFinishMediaWithInfoMethod before saving the captured image. The above method will return you an Uiimage with changed size (that you have to provide as CGSize).

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  UIImage * tempImage =[info objectForKey:UIImagePickerControllerOriginalImage];
  CGSize mSize;
   mSize     =  CGSizeMake(your width and height as per 5MP mode);
   tempImage = [ViewController  imageWithImage:tempImage scaledToSize:mSize];
  // use this temp img as it would be in dimensions of 5MP image.
}
Rana
  • 451
  • 4
  • 16
  • Thanks @Rana. Your answer is helpful.But I am trying to avoid resizing. And also I am looking into getting YUV/RGB buffer directly, if possible without processing. – thar_bun Jan 31 '14 at 11:58