B25Dec
B25Dec

Reputation: 2377

How can we Zoom a camera screen by programmatically in iphone?

Is this possible to Zoom the camera picture programmatically, I checked the APi provided by Apple for this but there is no API in the SDK for the zooming for the camera. There is only zooming functionality in the scroll view only, is there any way by which we can do the zoom our camera view.

Even some App on the appstore hve the zooming functionality, than how it is possible.

Upvotes: 2

Views: 3230

Answers (2)

Riddick
Riddick

Reputation: 400

Here is my solution: First you need to have a view in which you'll set your controls (you can write this on your viewDidLoad method):

UIView *miControllingView = [[UIView alloc]initWithFrame:CGRectMake(x,y,width,height)];

Then you implement a slider with values between 1 and 5 (this will make my image increase its size from 1x to 5x). Define this element on your .h file so you can access its value throughout your class:

zoom = [[UISlider alloc]initWithFrame:CGRectMake(sliderX, sliderY, sliderWidth, sliderHeight)];
[zoom setMaximumValue:5];
[zoom setMinimumValue:1];
[zoom setContinuous:YES];
[zoom addTarget:self action:@selector(zoomChange) forControlEvents:UIControlEventValueChanged];
[myControllingView addSubview:zoom];

Then you need to add your controlling view to the camera view with this:

[myPicker setCameraOverlayView:myControllingView];

Lastly, define the selector's behaviour:

-(void)zoomChange{
     [myPicker setCameraViewTransform:CGAffineTransformMakeScale([zoom value],[zoom value])];}

This works for me perfectly.

P.S. I also hide the camera controls so it looks neater with this:

myPicker.showsCameraControls = NO;

Upvotes: 1

James L
James L

Reputation: 16864

There is no hardware zoom on the iphone.

You'll have to scale up a cropped portion of the image.

Upvotes: 3

Related Questions