如何在下载网络图片之前获取图片的大小,以设置图片的frame?
如下:
#import <ImageIO/ImageIO.h>
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);
网友评论