3

I tried to add overlay when capturing the photo. i could successfully add the overlay in preview but once i tap the photo capture button,the overlay view (around 40px ) will upside down and also i tried to save the image in photo album but saved image does not contain the overlay image.

i attached the below, if i am wrong please guide me?

//In ViewDidLoad//
OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];

UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.sourceType = UIImagePickerControllerSourceTypeCamera;

picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;

[picker setDelegate:self];  
picker.showsCameraControls = YES;
picker.navigationBarHidden = YES;
picker.toolbarHidden = YES;



picker.wantsFullScreenLayout = YES;


picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, 1, 1.24299);


picker.cameraOverlayView = overlay;

[self presentModalViewController:picker animated:YES];  
[picker release];




- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

// Save image
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);


}



- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;

// Unable to save the image  
if (error)
    alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                       message:@"Unable to save image to Photo Album." 
                                      delegate:self cancelButtonTitle:@"Ok" 
                             otherButtonTitles:nil];
else // All is well
    alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                       message:@"Image saved to Photo Album." 
                                      delegate:self cancelButtonTitle:@"Ok" 
                             otherButtonTitles:nil];


[alert show];
alert.delegate = self;
[alert release];
}


//In OverlayView.m file

- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
    // Clear the background of the overlay:
    self.opaque = NO;
    self.backgroundColor = [UIColor clearColor];

    // Load the image to show in the overlay:
    UIImage *overlayGraphic = [UIImage imageNamed:@"img3.png"];
    UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
    overlayGraphicView.frame = CGRectMake(0, 50, 320, 430);
    [self addSubview:overlayGraphicView];
    [overlayGraphicView release];

}
return self;
}

Thanks in advace

thavasidurai
  • 1,972
  • 1
  • 26
  • 51

1 Answers1

5

Creating image after capturing photo like this:

UIImage *capturedImage = [UIImage imageNamed:@"bottom.png"]; //Captured image
UIImage *overlayImage  = [UIImage imageNamed:@"top.png"]; //foverlayImage image

CGSize newSize = capturedImage.size
UIGraphicsBeginImageContext( newSize );

[capturedImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

// Apply supplied opacity if applicable
[overlayImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.7];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
  • can i add this code in - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info method? – thavasidurai Sep 03 '12 at 12:57
  • set frame of overlay according u want – Paresh Navadiya Sep 03 '12 at 13:02
  • yes its working but overlay image is transparent with image taken by camera. – thavasidurai Sep 03 '12 at 13:09
  • Wouldn't there be a problem with this if the capturedImage and overlayImage had different sizes or aspect ratios? This is the problem I'm currently facing trying to do pretty much the same thing. The capturedImage is a from the camera, so its aspect ratio is 4:3, while the overlayImage's aspect ratio differs, so the overlyImage gets distorted (aspect ratio not preserved). – Peter Jacobs Aug 15 '13 at 05:48
  • @PeterJacobs I am having same issue of the aspect ratio (my overlay image size change when display the image).If anyone know this ,please help me... – Divyesh Dobariya Nov 01 '14 at 06:54