ios通过URL获取网络图片的原始大小

来源:互联网 发布:数据清洗工具kettle 编辑:程序博客网 时间:2024/05/21 15:02

有两种方法:


1、直接获取


NSData *data = [NSData dataWithContentsOfURL:[NSURLURLWithString:@"http://s12.mogujie.cn/b7/bao/131011/1jix9_kqywmrcdkfbg26dwgfjeg5sckzsew_400x540.jpg_200x999.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;

}];


0 0
原创粉丝点击