在UIImage上添加图像

时间:2011-10-08 03:53:02

标签: iphone ios uiimage core-graphics

我想在保存之前在UIImage上添加图片横幅。我已经创建了这种类别方法。我已检查并重新检查banner.png是否存在且gradient显示正常。

我做错了什么?

提前致谢!

- (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;
}

2 个答案:

答案 0 :(得分:1)

显然[UIImage imageWithContentsOfFile:]需要一条完整的路径。将其更改为[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"banner.png"]]

答案 1 :(得分:0)