簡體   English   中英

在UIImage頂部添加圖像

[英]Add image on top of UIImage

我試圖在保存之前在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;
}

顯然[UIImage imageWithContentsOfFile:]需要完整路徑。 將其更改為[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"banner.png"]]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM