方案一: 我们可以通过<ImageIO/ImageIO.h> 这个框架对图片进行硬解码 通过少量的网络请求来获取图片信息
NSURL *url = [NSURL URLWithString: xxximageUrlstr ];
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
CGFloat pixelWidth = [properties[(__bridge NSString *)kCGImagePropertyPixelWidth] doubleValue];
CGFloat pixelHeight = [properties[(__bridge NSString *)kCGImagePropertyPixelHeight] doubleValue];
本地图片获取宽高
UIImage *image = [UIImage imageNamed:dataModel.item_thumb];
CGFloat width = CGImageGetWidth(image.CGImage);
CGFloat height = CGImageGetHeight(image.CGImage);
网友评论