Add image on top of UIImage
I am trying to add a image banner on top of a UIImage
before saving it. I have created this category method to do so. I have checked a开发者_开发技巧nd rechecked that banner.png
exists and the gradient
shows up fine.
What am I doing wrong?
Thanks in advance!
- (UIImage *)addBanner {
UIGraphicsBeginImageContext(CGSizeMake(self.size.width, self.size.height+50));
[self drawAtPoint:CGPointMake(0, 50)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect bannerRect = CGRectMake(0, 0, self.size.width, 50);
CGColorRef start = RGB(71, 174, 255).CGColor;
CGColorRef end = RGB(0, 80, 255).CGColor;
drawLinearGradient(context, bannerRect, start, end);
UIImage *bannerImage = [UIImage imageWithContentsOfFile:@"banner.png"];
[bannerImage drawAtPoint:CGPointMake(0, 0)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Apparently [UIImage imageWithContentsOfFile:]
requires a full path. Changing it to [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"banner.png"]]
worked.
Please refer Combining Images with UIImage & CGContext – (Offscreen drawing)
精彩评论