Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVFoundation camera zoom

I use AVFoundation framework to display video from camera.

The code how i use it is usual:

session = [[AVCaptureSession alloc] init] ;
...   
captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
...
[cameraView.layer addSublayer:captureVideoPreviewLayer];
...

So i want to add zoom function to camera.

I have found 2 solutions how to implement zoom.

First : is to use CGAffineTransform:

cameraView.transform = CGAffineTransformMakeScale(x,y);

Second : is to put cameraView in the scroll view ,set up max and min scrolling and set this view as zooming view.

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return cameraView;
}

What is the best way to make zooming better performance and quality? Are there any else solutions to make zoom? Maybe i missed some AVFoundation methods for zooming.

Thank you.

like image 211
B.S. Avatar asked Mar 29 '13 11:03

B.S.


People also ask

Can I build my own camera control using AVFoundation?

The remainder of this blog post, though, will detail exactly how to build your own camera control using AVFoundation. AVFoundation is a namespace that contains classes for high-level recording and playback capabilities for audio and video on iOS.

Should I try the AVFoundation iOS simulator?

We encourage you to try it. Camera Manager has an example app that you can run on your device. You'll need a real device to run it, due to the use of AVFoundation camera API's which are unavailable on the iOS simulator. Ready for a UX Audit?

How to switch cameras in AV Foundation?

Let’s move on to switching cameras. Switching cameras in AV Foundation is a pretty easy task. We just need to remove the capture input for the existing camera and add a new capture input for the camera we want to switch to. Let’s add another function to our CameraController class for switching cameras:

What is AVFoundation in iOS?

Building a Custom Camera with AVFoundation AVFoundation is a namespace that contains classes for high-level recording and playback capabilities for audio and video on iOS. Many tasks, such as capturing and playing photos or videos, can be done without AVFoundation using techniques described earlier in this post.


Video Answer


1 Answers

Well there is actually a GCFloat called setVideoScaleandCropFactor.

You can find the documentation here.

I'm not sure if this is just for still image output but I've been working on it and it does well if you set it to a gesture or a slider and let that control the float.

You can find a demo of it here.

Good stuff. Im trying to loop it so I can create a barcode scanner with a zoom. What im doing is rough though haha.

like image 60
Nathan Kellert Avatar answered Nov 19 '22 10:11

Nathan Kellert