// 下载 - > 合并 - > 显示
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// @"http://img04.tooopen.com/images/20130712/tooopen_17270713.jpg"
// @"https://www.baidu.com/img/bd_logo1.png"
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// 下载第一张
NSString *urlString1 = [NSString stringWithFormat:@"http://img04.tooopen.com/images/20130712/tooopen_17270713.jpg"];
// 下载第二张
NSString *urlString2 = [NSString stringWithFormat:@"https://www.baidu.com/img/bd_logo1.png"];
NSURL *url1 = [NSURL URLWithString:urlString1];
NSURL *url2 = [NSURL URLWithString:urlString2];
UIImage *image1 = [UIImage imageWithData:[NSData dataWithContentsOfURL:url1]];
UIImage *image2 = [UIImage imageWithData:[NSData dataWithContentsOfURL:url2]];
// 得到图片上下文
// ou use this function to configure the drawing environment for rendering into a bitmap.
// 用这个函数 配置或者装载 用来表现 图片的环境
UIGraphicsBeginImageContextWithOptions(image1.size, NO, 0.0f);
// 绘制图片
[image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];
[image2 drawInRect:CGRectMake(0, 0, image2.size.width, image2.size.height)];
// 得到上下文的图片
UIImage *fullImage = UIGraphicsGetImageFromCurrentImageContext();
// 返回主队列
dispatch_async(dispatch_get_main_queue(), ^{
self.imageView.image = fullImage;
});
// 结束上下文
UIGraphicsEndImageContext();
});
}
GCD队列组1
最新推荐文章于 2024-09-14 08:31:55 发布