采用UIGraphics将两幅图绘制到同一个画布上输出,达到图像融合的简单效果。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| UIImage *supermanImage = [UIImage imageNamed:@"superman.png"]; UIImage *moneyImage = [UIImage imageNamed:@"money.png"]; CGSize supermanSize = [supermanImage size]; CGSize moneySize = [moneyImage size];
UIGraphicsBeginImageContext(supermanSize); [supermanImage drawInRect:CGRectMake(0, 0, supermanSize.width, supermanSize.height)]; [moneyImage drawInRect:CGRectMake(0, 0, moneySize.width, moneySize.height)]; UIImage *mergeImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); mergeImageView = [[UIImageView alloc] init]; mergeImageView.image = mergeImage; mergeImageView.frame = self.view.bounds; [self.view addSubview:mergeImageView];
|
demo地址:https://github.com/depthlove/STMImageMerging