Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. Tint the Image
- NSString *name = @"Skyline.png";
- UIImage *imgBottomCrop = [UIImage imageNamed:name];
- // begin a new image context, to draw our colored image onto
- UIGraphicsBeginImageContext(imgBottomCrop.size);
- // get a reference to that context we created
- CGContextRef context = UIGraphicsGetCurrentContext();
- // set the fill color
- [[UIColor redColor] setFill];
- // translate/flip the graphics context (for transforming from CG* coords to UI* coords
- CGContextTranslateCTM(context, 0, imgBottomCrop.size.height);
- CGContextScaleCTM(context, 1.0, -1.0);
- // set the blend mode to color burn, and the original image
- CGContextSetBlendMode(context, kCGBlendModeColorBurn);
- CGRect rectBottomCrop = CGRectMake(0, 0, img.size.width, img.size.height);
- CGContextDrawImage(context, rectBottomCrop, imgBottomCrop.CGImage);
- // set a mask that matches the shape of the image, then draw (color burn) a colored rectangle
- CGContextClipToMask(context, rectBottomCrop, imgBottomCrop.CGImage);
- CGContextAddRect(context, rectBottomCrop);
- CGContextDrawPath(context,kCGPathFill);
- // generate a new UIImage from the graphics context we drew onto
- UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- // Display Image
- displayPicture2.image = coloredImg;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement