【发布时间】:2014-03-25 17:32:08
【问题描述】:
我想在 iOS 中用另一张图片填充图片的透明部分。
我用UIGraphicsContext 尝试了一些东西,但我无法让它工作,因为我以前从未使用过它。
图片如下:
我试过的一些代码:
UIImageView *v = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 70, 70)];
UIGraphicsBeginImageContextWithOptions(v.frame.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// beach image
UIImage *img = [UIImage imageNamed:@"zivogosce_camping_05.jpg"];
//[img drawInRect:CGRectMake(2, 0, 12, 12)];
UIImage *annotationImg = [UIImage imageNamed:@"custom_annotation"];
[annotationImg drawAtPoint:CGPointMake(0, 0)];
CGContextSetFillColorWithColor(context, [[UIColor colorWithPatternImage:img] CGColor]);
CGContextFillRect(context, CGRectMake(0, 0, 50, 50));
CGContextDrawImage(context, CGRectMake(0, 0, v.frame.size.width, v.frame.size.height), [annotationImg CGImage]);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
[v setImage:newImage];
UIGraphicsEndImageContext();
但是图片不太合适...
【问题讨论】:
-
你为什么不把它画在另一张图片上?
-
请发布一些代码,以便我们帮助您确定问题所在。你现在画得怎么样?
标签: ios uiimage transparent fill uigraphicscontext