码迷,mamicode.com
首页 > 编程语言 > 详细

GCD开启子线程下载图片

时间:2016-04-26 09:37:52      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

    //开启子线程下载图片

   //1.获取一个全局串行队列
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    __weak typeof(self) weakSelf = self;

   //2.把任务添加到队列中执行
    dispatch_async(queue, ^{
        NSURL *url = [NSURL URLWithString:_imgString];
        NSData *imageData = [NSData dataWithContentsOfURL:url];
        UIImage * bgImage = [UIImage imageWithData:imageData];
        bgImage = [bgImage applyLightEffectAtFrame:CGRectMake(0, 0, bgImage.size.width, bgImage.size.height)];
        //3.回到主线程
        dispatch_async(dispatch_get_main_queue(), ^{
            weakSelf.backImageView.image = bgImage;
        });
    });

GCD开启子线程下载图片

标签:

原文地址:http://www.cnblogs.com/Crazy-ZY/p/5433710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!