美文网首页
iOS通过URL获取网络图片的原始大小

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

作者: Justin_W | 来源:发表于2017-07-03 13:49 被阅读0次

    1、直接获取

    NSData*data = [NSDatadataWithContentsOfURL:[NSURLURLWithString:@"http://s12.mogujie.cn/b7/bao/131011/1jix9_kqywmrcdkfbg26dwgfjeg5sckzsew_400x540.jpg_200x999.jpg"]];

    UIImage*image = [UIImageimageWithData:data];

    NSLog(@"w = %f,h = %f",image.size.width,image.size.height);

    2、//需要用到第三方库SDWebImage

    UIImageView*v1 = [[UIImageViewalloc]init];

    [self.viewaddSubview:v1];

    [v1sd_setImageWithURL:[NSURLURLWithString:imageNameplaceholderImage:[UIImageimageNamed:@"default1"]options:SDWebImageRetryFailedcompleted:^(UIImage*image,NSError*error,SDImageCacheTypecacheType,NSURL*imageUrl){

    CGSizesize = image.size;

    CGFloatw = size.width;

    CGFloatH = size.height;

    }];

    相关文章

      网友评论

          本文标题:iOS通过URL获取网络图片的原始大小

          本文链接:https://www.haomeiwen.com/subject/fipacxtx.html