一個線程安全的,高性能,功能豐富的圖像下載iOS庫:PINRemoteImage
一個線程安全的,高性能,功能豐富的圖像下載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:@"(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;
}];</pre>
</span>