简体   繁体   English

如何使用8MP相机在iPhone设备中捕获5MP图像?

[英]How to capture 5MP Image in iPhone devices with 8MP camera?

I want to capture images with 5 MP resolution in an iOS device where maximum image sensor capture resolution is 8 MP. 我想在最大图像传感器捕获分辨率为8 MP的iOS设备中捕获5 MP分辨率的图像。

The presets provided in Avfoundations AVCaptureSessionPresetPhoto gives - 3264x2448 - 8 MP resolution VCaptureSessionPresetHigh gives - 1920x1080 - 2 MP resolution Avfoundations AVCaptureSessionPresetPhoto中提供的预设提供-3264x2448-8 MP分辨率VCaptureSessionPresetHigh提供-1920x1080-2 MP分辨率

Is there any way/workaround for capturing 5MP directly, instead of capturing 8MP and then downscaling? 有什么方法/解决方法可以直接捕获5MP,而不是捕获8MP然后缩减规模?

iOS gives very limited output resolutions from Camera. iOS提供的Camera输出分辨率非常有限。

You mentioned correctly that largest size is 8MP and next preset goes down to 1080p or ~2MP. 您正确提到最大大小为8MP,下一个预设值降至1080p或〜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. 似乎期望按照应用程序的要求缩小/裁剪图像,但是SDK没有提供单个API来获得所需的分辨率或输出图像。

Hope this helps. 希望这可以帮助。

AVCaptureSessionPreset gives only constants resolutions (You can see API references). AVCaptureSessionPreset仅提供常量解析度(您可以参阅API参考)。 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 wrt 5MP resolution using following method 为什么不使用8MP相机捕获图像,然后在保存图像之前使用以下方法将其大小更改为5MP分辨率

+ (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. 在保存捕获的图像之前,请在imagePickerDidFinishMediaWithInfoMethod中调用上述方法。 The above method will return you an Uiimage with changed size (that you have to provide as CGSize). 上面的方法将返回一个大小已更改的Uiimage(您必须提供为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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM