Reputation: 6164
In iPhone App,
I want to implement digital zooming in my iphone app while capturing photograph using iphone camera.
How can I do that ?
Upvotes: 0
Views: 1106
Reputation: 19479
Once you have captured the image, I think you can do using the scaling and cropping images to the size you want.
But the clarity of the images may not be the same as original one.
- (UIImage *)image
{
if (cachedImage == nil) {
// HERE YOU CAN GIVE THE FRAME YOU WANT THE SIZE OF THE IMAGE TO BE.
CGRect imageFrame = CGRectMake(0, 0, 400, 300);
UIView *imageView = [[UIView alloc] initWithFrame:imageFrame];
[imageView setOpaque:YES];
[imageView setUserInteractionEnabled:NO];
[self renderInView:imageView withTheme:nil];
UIGraphicsBeginImageContext(imageView.bounds.size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextGetCTM(c);
CGContextScaleCTM(c, 1, -1);
CGContextTranslateCTM(c, 0, -imageView.bounds.size.height);
[imageView.layer renderInContext:c];
cachedImage = [UIGraphicsGetImageFromCurrentImageContext() retain];
// rescale image
UIImage* bigImage = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef scaledImage = [self newCGImageFromImage:[bigImage CGImage] scaledToSize:CGSizeMake(100.0f, 75.0f)];
cachedImage = [[UIImage imageWithCGImage:scaledImage] retain];
CGImageRelease(scaledImage);
UIGraphicsEndImageContext();
[imageView release];
}
return cachedImage;
}
Hope this helps you.
Upvotes: 1
Reputation: 135578
UIImagePickerController
has a cameraViewTransform
that you can use to scale the camera view when the user zooms. After the image has been captured, it is then up to you to crop and resize it according to the zoom setting.
To do that, you would create a new graphics context with the desired size and draw the image you got from the image picker into that context.
Upvotes: 2