Advertisement
Guest User

Untitled

a guest
Aug 21st, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. // 1. Tint the Image
  2. NSString *name = @"Skyline.png";
  3. UIImage *imgBottomCrop = [UIImage imageNamed:name];
  4. // begin a new image context, to draw our colored image onto
  5. UIGraphicsBeginImageContext(imgBottomCrop.size);
  6. // get a reference to that context we created
  7. CGContextRef context = UIGraphicsGetCurrentContext();
  8. // set the fill color
  9. [[UIColor redColor] setFill];
  10. // translate/flip the graphics context (for transforming from CG* coords to UI* coords
  11. CGContextTranslateCTM(context, 0, imgBottomCrop.size.height);
  12. CGContextScaleCTM(context, 1.0, -1.0);
  13. // set the blend mode to color burn, and the original image
  14. CGContextSetBlendMode(context, kCGBlendModeColorBurn);
  15. CGRect rectBottomCrop = CGRectMake(0, 0, img.size.width, img.size.height);
  16. CGContextDrawImage(context, rectBottomCrop, imgBottomCrop.CGImage);
  17. // set a mask that matches the shape of the image, then draw (color burn) a colored rectangle
  18. CGContextClipToMask(context, rectBottomCrop, imgBottomCrop.CGImage);
  19. CGContextAddRect(context, rectBottomCrop);
  20. CGContextDrawPath(context,kCGPathFill);
  21. // generate a new UIImage from the graphics context we drew onto
  22. UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
  23. UIGraphicsEndImageContext();
  24. // Display Image
  25. displayPicture2.image = coloredImg;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement