Mitesh Khatri
Mitesh Khatri

Reputation: 3955

Open iPhone camera in a frame

I want to open iPhone camera in a frame. Actually I have a image in Heart shape. So I want to open camera in this image. So please can any one suggest me how I do this.

Thanks

Upvotes: 3

Views: 1714

Answers (2)

ManjotSingh
ManjotSingh

Reputation: 711

Below are the steps for getting framed image with camera click:

1 Open a view which is containing cut image of heart shape frame.

UIImage *image = [UIImage imageNamed:@"myimage.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake( 0, 0, cell.frame.size.width, cell.frame.size.height );
imageView.contentMode = UIViewContentModeScaleToFill;

2 Call camera overlay below that cut heart shape image to use camera for snapping images.

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = (sender == takePictureButton) ? UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController: picker animated:YES];
[picker release];

3 Click the image let the image view be there and enable snapped image editable.

4 Then take screen shot with heart shape image view to get your image as per your requirement.

UIGraphicsBeginImageContext(webview.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

Upvotes: 2

spring
spring

Reputation: 18507

UIImagePickerController has an cameraOverlayView property. I haven't tried it but I imagine you can add a UImageView as a subView of that, using an image with an alpha channel to mask the areas you don't want the camera to show through.

Why not give it a try and report back on how it works.

cameraOverlayView

The custom view to display on top of the default image picker interface. @property (nonatomic, retain) UIView *cameraOverlayView Discussion

You can use an overlay view to present a custom view hierarchy on top of the default image picker interface. The image picker layers your custom overlay view on top of the other image picker views and positions it relative to the screen coordinates. If you have the default camera controls set to be visible, incorporate transparency into your view, or position it to avoid obscuring the underlying content.

Upvotes: 0

Related Questions