一个线程安全的,高性能,功能丰富的图像下载iOS库:PINRemoteImage

jopen 9年前

一个线程安全的,高性能,功能丰富的图像下载iOS库。快速,无死锁并行图像下载和缓存。

PINRemoteImageManager is an image downloading, processing and caching manager. It uses the concept of download and processing tasks to ensure that even if multiple calls to download or process an image are made, it only occurs one time (unless an item is no longer in the cache). PINRemoteImageManager is backed by GCD and safe to access from multiple threads simultaneously. It ensures that images are decoded off the main thread so that animation performance isn't affected. None of its exposed methods allow for synchronous access. However, it is optimized to call completions on the calling thread if an item is in its memory cache.

下载一张图片并把它设置在一个image view中:

UIImageView *imageView = [[UIImageView alloc] init];  [imageView pin_setImageFromURL:[NSURL URLWithString:@"http://pinterest.com/kitten.jpg"]];

下载和处理一张图片

UIImageView *imageView = [[UIImageView alloc] init];  [self.imageView pin_setImageFromURL:[NSURL URLWithString:@"https://s-media-cache-ak0.pinimg.com/736x/5b/c6/c5/5bc6c5387ff6f104fd642f2b375efba3.jpg"] processorKey:@"rounded" processor:^UIImage *(PINRemoteImageManagerResult *result, NSUInteger *cost)   {       CGSize targetSize = CGSizeMake(200, 300);       CGRect imageRect = CGRectMake(0, 0, targetSize.width, targetSize.height);       UIGraphicsBeginImageContext(imageRect.size);       UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:imageRect cornerRadius:7.0];       [bezierPath addClip];         CGFloat sizeMultiplier = MAX(targetSize.width / result.image.size.width, targetSize.height / result.image.size.height);         CGRect drawRect = CGRectMake(0, 0, result.image.size.width * sizeMultiplier, result.image.size.height * sizeMultiplier);       if (CGRectGetMaxX(drawRect) > CGRectGetMaxX(imageRect)) {           drawRect.origin.x -= (CGRectGetMaxX(drawRect) - CGRectGetMaxX(imageRect)) / 2.0;       }       if (CGRectGetMaxY(drawRect) > CGRectGetMaxY(imageRect)) {           drawRect.origin.y -= (CGRectGetMaxY(drawRect) - CGRectGetMaxY(imageRect)) / 2.0;       }         [result.image drawInRect:drawRect];         UIImage *processedImage = UIGraphicsGetImageFromCurrentImageContext();       UIGraphicsEndImageContext();       return processedImage;   }];

项目主页:http://www.open-open.com/lib/view/home/1438440893300