Depth.Love Blog

GitHub:https://github.com/depthlove

0%

在iOS上硬编码推流-图像融合(二)

采用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];

// NSLog(@"s : %f,%f \n m : %f,%f", supermanSize.width, supermanSize.height, moneySize.width, moneySize.height);

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