有两种方法:
1、直接获取
NSData *data = [NSData dataWithContentsOfURL:[NSURLURLWithString:@"https://image.11xiuge.com/public/2016-11-23/ca789c2e6a532f00b49aaa474ec46bec.jpg"]];
UIImage *image = [UIImage imageWithData:data];
NSLog(@"w = %f,h = %f",image.size.width,image.size.height);
2、//需要用到第三方库SDWebImage
UIImageView *v1 = [[UIImageViewalloc]init];
[self.viewaddSubview:v1];
[v1 sd_setImageWithURL:[NSURLURLWithString:imageName placeholderImage:[UIImageimageNamed:@"default1"]options:SDWebImageRetryFailedcompleted:^(UIImage *image,NSError *error,SDImageCacheType cacheType,NSURL *imageUrl){
CGSize size = image.size;
CGFloat w = size.width;
CGFloat H = size.height;
}];
网友评论