开发者

Add image on top of UIImage

开发者 https://www.devze.com 2023-04-11 19:42 出处:网络
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 gradien

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号