如何从 SDWebImage 获取图像大小?

How to get image size from SDWebImage?

我正在使用 SDWebImage 从 url 获取图像。我想获取远程图像的大小以便进行一些布局计算。由于我只知道图像的 url ,我如何从 SDWebImage 对象中获取它?

请试试这个,它可能适合你

-(UIImage *)downloadImageAsync:(NSString *)imageKey
 {
     NSLog(@"image key : %@",imageKey);
      __block UIImage *returnedImage;
     SDWebImageManager *manager = [SDWebImageManager sharedManager];
     [manager downloadWithURL:[NSURL URLWithString:imageKey] options:0 progress:^(NSUInteger receivedSize, long long expectedSize){
    NSLog(@"received size %d expected size %lld", receivedSize, expectedSize);

    }completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType,BOOL finished){
      if(image && finished) {
        returnedImage = image;
      }
   }];

   if(returnedImage == nil) {
      NSLog(@"Returned Image Nil");
   }
    return returnedImage;
}