Skip to content

Instantly share code, notes, and snippets.

View d4rkd3v1l's full-sized avatar
😈
1337

Martin Straub d4rkd3v1l

😈
1337
View GitHub Profile
@d4rkd3v1l
d4rkd3v1l / Image.m
Last active November 29, 2017 14:33
iOS: How to retrieve image dimensions without loading CGImage into memory
// This method requires ImageIO.framework
#import <ImageIO/ImageIO.h>
- (CGSize)sizeOfImageAtURL:(NSURL *)imageURL
{
// With CGImageSource we avoid loading the whole image into memory
CGSize imageSize = CGSizeZero;
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)imageURL, NULL);
if (source) {
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:(NSString *)kCGImageSourceShouldCache];