4

Special Thanks in advance...... I m the beggininer in iphone software development.

Just looking for how to programmatically add real time a watermark image to camera view using cocoa. Not looking for a step by step ( although that would awesome ), but more or less looking for where I should start looking to learn how. Are there frameworks developed to work for this. Would like something native to objective-C using XCode framework because I would like to eventually give this a go on the iPhone. Any help would be great.

Tirth
  • 7,801
  • 9
  • 55
  • 88
  • 1
    Hey Rajendra! If my answer is useful enough for you mark then accept it. If not ask your questions in comments and I'll see if I can help. – Ivan Karpan Jan 21 '10 at 15:53

1 Answers1

4

UPDATE: here's my other answer about how this overlay view can be put under the camera animations: camera overlay view - just for preview?

Helo Rajendra!

I've created a simple Window-based iPhone OS Application to give you a very simple example on what and how should be done to capture photos with camera, overlay views in camera mode, resize and merge images. This project is actually has only AppDelegate header and implementation files and can be easily reproduced in XCode.

Here's the header file:

//
//  CameraWatermarkAppDelegate.h
//  CameraWatermark
//
//  Created by Ivan Karpan on 1/16/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface CameraWatermarkAppDelegate : NSObject < UIApplicationDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate > {
    UIImageView *imageView;
    UIViewController *viewController;
    UIWindow *window;
}

@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIViewController *viewController;
@property (nonatomic, retain) IBOutlet UIWindow *window;


@end

And here's the implementation file:

//
//  CameraWatermarkAppDelegate.m
//  CameraWatermark
//
//  Created by Ivan Karpan on 1/16/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "CameraWatermarkAppDelegate.h"


const float WATERMARK_ALPHA = 0.5;


@implementation CameraWatermarkAppDelegate

@synthesize imageView, viewController, window;


- (void)applicationDidFinishLaunching:(UIApplication *)application {
    self.viewController = [[UIViewController new] autorelease];
    viewController.view.backgroundColor = [UIColor blackColor];

    // An image view to save to (and therefore display) the captured image
    self.imageView = [[UIImageView new] autorelease];
    imageView.frame = viewController.view.frame;
    [viewController.view addSubview:imageView];

    [window addSubview:viewController.view];

    UIImagePickerController *anImagePickerController = [UIImagePickerController new];
    anImagePickerController.delegate = self;
    anImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

    {// This block of code is only needed in case you want your watermark to be displayed also during the shooting process
        UIImageView *anImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Watermark.png"]];
        anImageView.alpha = WATERMARK_ALPHA;
        anImageView.contentMode = UIViewContentModeTopLeft;
        anImageView.frame = viewController.view.frame;
        anImagePickerController.cameraOverlayView = anImageView;
        [anImageView release];
    }

    // From the very beginning we simply present the image picker controller
    [viewController presentModalViewController:anImagePickerController animated:NO];
    [anImagePickerController release];
}


- (void)dealloc {
    [imageView release];
    [viewController release];
    [window release];
    [super dealloc];
}

#pragma mark UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIGraphicsBeginImageContext(CGSizeMake(320, 480));
    // This is where we resize captured image
    [(UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage] drawInRect:CGRectMake(0, 0, 320, 480)];
    // And add the watermark on top of it
    [[UIImage imageNamed:@"Watermark.png"] drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeNormal alpha:WATERMARK_ALPHA];
    // Save the results directly to the image view property
    imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    // Dismiss the image picker controller and look at the results
    [picker dismissModalViewControllerAnimated:YES];
}


@end

I hope this will serve you as a starting point.

Community
  • 1
  • 1
Ivan Karpan
  • 1,554
  • 15
  • 20
  • Ivan, I now this is an old post but it was very helpful, however I do have one problem... the overlay image seems to be offset in the final merged image. Any way to correct this? I think it has to do with scaling and the camera's aspect ratio, but I am not sure. Any ideas? – LilMoke Apr 18 '12 at 12:11
  • Well in your situation I would simply tried making transformations on the watermark image. If you want you can post your question with snippets of code enough for me to start a new project, paste the code in it and play around with it. Maybe I will be able to help. Just be sure to send me a message with a link if you will decide to post the question. – Ivan Karpan Apr 19 '12 at 07:03
  • I have posted a question and code here: http://stackoverflow.com/questions/10226764/watermark-image-on-camera-view-is-offset Thanks for the help!! – LilMoke Apr 19 '12 at 11:09