1
我想用iOS中的另一個圖像填充圖像的透明部分。UIImage用另一個圖像填充透明部分
我嘗試了一些東西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();
但圖像不合身......
你爲什麼不在其他圖像上繪製它? –
請張貼一些代碼,以便我們可以幫助您確定問題所在。你現在怎麼畫? – user1118321