如何使用Avcapture设置帧大小 [英] How to set frame size using Avcapture

查看:156
本文介绍了如何使用Avcapture设置帧大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AVCaptureSession 拍照。这是我的代码:

I am using AVCaptureSession for taking pictures. Here is my code:

AVCaptureSession * newSession = [[AVCaptureSession alloc] init];

// Configure our capturesession
newSession.sessionPreset = AVCaptureSessionPresetMedium;

我的图片大小为360 * 480。但这是我的问题,我想要的图像完全是280 * 200的大小。我对裁剪图像不感兴趣。以任何方式设置图像大小 AVCaptureSession ?在此先感谢..

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..

推荐答案

使用AVCapturePresets,您可以获得明确的视频或照片。拍摄照片后,您可以操作(裁剪,调整大小)以适合所需的尺寸,但无法设置预定的拍摄尺寸。

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.

有可接受的预设:

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

我使用的方法可以帮助您扩展到所需的大小:

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");
}

这篇关于如何使用Avcapture设置帧大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆