实现“缩放”功能在AVCamViewController [英] Implementing "Zoom" feature in AVCamViewController

查看:186
本文介绍了实现“缩放”功能在AVCamViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程式中实作「缩放」功能。我的应用程序只支持静态图像,没有视频捕获等。我认为应该直接,但是,我可以缩放图像,然而,当我拍摄一个stillImage,图像出来作为完整的图像,没有放大/输出效果。
我使用Apple提供的AVCamViewController类。
如果你们指出我错过了什么,我会很感激。

I'm trying to implement "Zoom" feature in my app. My app only supports Still Image, no video capturing etc.. i thought it should be straight forward however, i'm able to zoom the image however when i take a stillImage, the image comes out as full image, no zoom-in/out effects. I'm using AVCamViewController class provided by Apple. I would appreciate if you guys point what i'm missing.

- (IBAction)zoomView {
    self.zoomScale =  1 + self.zoomSlider.value;
    self.previewView.transform = CGAffineTransformScale(CGAffineTransformIdentity,self.zoomScale, self.zoomScale);

    DLog(@"zoom scale:%f",self.zoomScale);
}


推荐答案

代码,那么我建议在AVCaptureDeviceInput对象上执行缩放,而不是缩放视图。

If you are using Apple's sample code, then I would suggest performing the zoom on the on the AVCaptureDeviceInput object as opposed to zooming a view.

例如,这是我在UIGestureRecognizer处理pinch手势):

For instance, this is how I do it within a UIGestureRecognizer (that handles pinch gestures):

dispatch_async(self.sessionQueue, ^{
    AVCaptureDevice *device = [[self getActiveVideoDeviceInput] device];
    NSError *error = nil;
    if ([device lockForConfiguration:&error])
    {
        device.videoZoomFactor = MAX(scale, 1.0);
        [device unlockForConfiguration];
    }
    else
    {
        NSLog(@"%@", error);
    }
});

这篇关于实现“缩放”功能在AVCamViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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