Вопрос

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?

Это было полезно?

Решение

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.

Другие советы

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

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.
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top