GCD开启子线程下载图片

    //开启子线程下载图片

   //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;
        });
    });

posted @ 2016-04-26 09:10  Crazy_ZY  阅读(423)  评论(0编辑  收藏  举报