Created
October 10, 2013 07:37
-
-
Save warriorg/6914480 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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); | |
char* text= (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding]; | |
CGContextSelectFont(context, "Arial",20, kCGEncodingMacRoman); | |
CGContextSetTextDrawingMode(context, kCGTextFill); | |
CGContextSetRGBFillColor(context, 0, 0, 0, 1); | |
CGContextShowTextAtPoint(context,10,10,text, strlen(text)); | |
CGImageRef imgCombined = CGBitmapContextCreateImage(context); | |
CGContextRelease(context); | |
CGColorSpaceRelease(colorSpace); | |
UIImage *retImage = [UIImage imageWithCGImage:imgCombined]; | |
CGImageRelease(imgCombined); | |
return retImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment