iOS获取网络图片的大小

如何在下载网络图片之前获取图片的大小,以设置图片的frame?

如下:

#import 

NSMutableString *imageURL = [NSMutableString stringWithFormat:@"http://www.myimageurl.com/image.png"];

CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)[NSURL URLWithString:imageURL], NULL);
NSDictionary* imageHeader = (__bridge NSDictionary*) CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
NSLog(@"Image header %@",imageHeader);
CGFloat pixelHeight = [[imageHeader objectForKey:@"PixelHeight"] floatValue];
CGFloat pixelWidth  = [[imageHeader objectForKey:@"PixelWidth"] floatValue];
CGSize size = CGSizeMake(pixelWidth, pixelHeight);

你可能感兴趣的:(iOS获取网络图片的大小)