PrasadW
PrasadW

Reputation: 427

How can I add a text label on a photo taken on iPhone/iPad using iOS5 or iOS6?

I just want to put the current geolocation on a photo taken from my iPhone/iPad.Is this possible?I have already got the geolocation but can I edit the photo programmatically by adding a text label over it.

Thanks for any help.

Upvotes: 0

Views: 3341

Answers (2)

Nishant Tyagi
Nishant Tyagi

Reputation: 9913

You can add text on image using :

//Add text to UIImage
-(UIImage *)addText:(UIImage *)img text:(NSString *)text1{
    int w = img.size.width;
    int h = img.size.height; 
    //lon = h - lon;
    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];
}

Hope it helps you.

Upvotes: 2

taffarel
taffarel

Reputation: 4045

here is the sample method which will return you a image with text on it

-(UIImage*) getImageWithText:(UIImage*) sourceImage
    {
        UIGraphicsBeginImageContext(sourceImage.size);
        [sourceImage drawAtPoint:CGPointZero];
    [@"someText" drawAtPoint:CGPointMake(x,y) [UIFont systemFontOfSize:14]]
    UIImage* imageWithText = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return imageWithText;
    }

Upvotes: 2

Related Questions