Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. //Add text to UIImage
  2.  
  3. -(UIImage *)addText:(UIImage *)img text:(NSString *)text1{
  4. int w = img.size.width;
  5. int h = img.size.height;
  6. //lon = h - lon;
  7. CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  8. CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
  9. CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);
  10. CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1);
  11. char* text = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding];// "05/05/09";
  12. CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman);
  13. CGContextSetTextDrawingMode(context, kCGTextFill);
  14. CGContextSetRGBFillColor(context, 255, 255, 255, 1);
  15.  
  16. //rotate text
  17. CGContextSetTextMatrix(context, CGAffineTransformMakeRotation( -M_PI/4 ));
  18. CGContextShowTextAtPoint(context, 4, 52, text, strlen(text));
  19. CGImageRef imageMasked = CGBitmapContextCreateImage(context);
  20. CGContextRelease(context);
  21. CGColorSpaceRelease(colorSpace);
  22. return [UIImage imageWithCGImage:imageMasked];
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement