Search code examples
cocoa-touchcore-locationios6.1

take photo with date using objective c


Is that possible to take photo from camera along with date, time and location(lat n long) display in photo in iphone.


Solution

  • Yes this is possible,

    You need to use UIImagePickerController with a custom overlay view...

    From Apple's docs @ http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

    You can customize an image picker controller to manage user interactions yourself. To do this, provide an overlay view containing the controls you want to display, and use the methods described in “Capturing Still Images or Movies.” You can display your custom overlay view in addition to, or instead of, the default controls. Custom overlay views for the UIImagePickerController class are available in iOS 3.1 and later by way of the cameraOverlayView property. For a code example, see the PhotoPicker sample code project.

    Further more, you can get all the data you need, time, geo coordinates etc from UIImagePickerControllerMediaMetadata

    Which you can use to populate labels on your custom overlay view.

    If you don't want to use this method you can also do it easily using AVCamCaptureManager and AVCamRecorder classes.

    As Per This Questions answer...

    "Apple has a demo program build on its developer site here. It is named AVCam. In simple words what it does is when you click to open the camera, it calls the classes and methods which are responsible for opening the iPhone's camera and record video or capture audio. It calls the same classes which are called by UIImagePickerController. So your camera will open and start taking input. Now, if you open the xib file of that AVCam project, you'll find a small UIView object. This view is responsible for displaying the camera's feed. You can resize that view as per the size you want and the camera's input will be displayed in that much area. You can also put the frame image around it as per your choice."

    Code to add strings to UIImage after taking picture:

    //Add text to UIImage
    
    -(UIImage *)addText:(UIImage *)img text:(NSString *)text1{
    
        int w = img.size.width;
    
        int h = img.size.height; 
    
    
    
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    
        CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
    
    
    
        CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
    
        CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1);
    
        char* text  = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];// "05/05/09";
    
        CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman);
    
        CGContextSetTextDrawingMode(context, kCGTextFill);
    
        CGContextSetRGBFillColor(context, 255, 255, 255, 1);
    
    
    
        //rotate text
    
        CGContextSetTextMatrix(context, CGAffineTransformMakeRotation( -M_PI/4 ));
    
        CGContextShowTextAtPoint(context, 4, 52, text, strlen(text));
    
        CGImageRef imageMasked = CGBitmapContextCreateImage(context);
    
        CGContextRelease(context);
    
        CGColorSpaceRelease(colorSpace);
    
        return [UIImage imageWithCGImage:imageMasked];
    
    }