【发布时间】:2011-10-08 03:53:02
【问题描述】:
我正在尝试在保存之前在 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;
}
【问题讨论】:
-
运行这段代码会发生什么?
-
我的图像顶部带有横幅渐变,但没有显示横幅图像。
-
原来 bannerImage 是 nil ,所以这导致了我的问题。我绝对肯定它在应用程序包中。
标签: iphone ios uiimage core-graphics