Watermark image on real time on camera view in iphone

前端 未结 1 608
感动是毒
感动是毒 2021-01-06 05:35

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 camer

相关标签:
1条回答
  • 2021-01-06 05:56

    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.

    0 讨论(0)
提交回复
热议问题