Created
          August 3, 2012 15:15 
        
      - 
      
- 
        Save genkernel/3248548 to your computer and use it in GitHub Desktop. 
    iOS. Load image downsampled to specified max pixel size.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | + (UIImage *)thumbnailImageFromURL:(NSURL*)imageUrl downsampledToMaxPixelSize:(NSNumber *)maxPixelSize { | |
| NSDictionary *opts = @{ | |
| (id)kCGImageSourceThumbnailMaxPixelSize: maxPixelSize, | |
| (id)kCGImageSourceCreateThumbnailWithTransform: (id)kCFBooleanTrue, | |
| (id)kCGImageSourceCreateThumbnailFromImageIfAbsent: (id)kCFBooleanTrue | |
| }; | |
| CGImageSourceRef src = CGImageSourceCreateWithURL((__bridge CFURLRef)imageUrl, NULL); | |
| CGImageRef thumbnail = CGImageSourceCreateThumbnailAtIndex(src, 0, (__bridge CFDictionaryRef)opts); | |
| UIImage *img = [UIImage imageWithCGImage:thumbnail]; | |
| CGImageRelease(thumbnail); | |
| CFRelease(src); | |
| return img; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment