从网址快速加载图片 [英] load image fastly from url

查看:102
本文介绍了从网址快速加载图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用SDWebimages类将图像从url加载到图像视图。但它仍然需要时间来加载。

I have used SDWebimages classes for loading the image from url to image view. But it is still taking time to load.

 NSString *filePath1 = [NSString stringWithFormat:@"%@",pathimage1];
 [cell.image1 setImageWithURL:[NSURL URLWithString:filePath1]placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

谁能告诉我我做错了什么?或者从网址加载图片的最佳方式。

Can anyone tell me what I am doing wrong? Or the best way to load the image from url.

推荐答案

从网络加载图片可能需要很长时间才能加载原因,两个最明显的原因是

Loading images from the network may take a long time to load for several reasons, two of the most obvious being


  • 设备上的互联网连接速度慢(Wifi / 3G / 2G)。

  • 服务器过载。

如果您可以控制服务器和存储的图像,可以加快速度在它上面你总是可以加载一个较小的版本(低质量的预览/缩略图),然后在需要时加载一个更大/全尺寸的版本:

To speed things up if you have control over the server and the images that are stored on it you could always load a smaller version (low quality preview/thumbnail) initially, followed by loading a larger / full-size version when needed:

typedef enum {
  MyImageSizeSmall,
  MyImageSizeMedium,
  MyImageSizeLarge
} MyImageSize;

-(void)requestAndLoadImageWithSize:(MyImageSize)imageSize intoImageView:(UIImageView *)imageView
{
  NSString *imagePath
  switch (imageSize)
  {
    case MyImageSizeSmall:
      imagePath = @"http://path.to/small_image.png";
    break;
    case MyImageSizeMedium:
      imagePath = @"http://path.to/medium_image.png";
    break;
    case MyImageSizeLarge:
      imagePath = @"http://path.to/large_image.png";
    break;
  }
  [imageView setImageWithURL:[NSURL URLWithString:imagePath]
            placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
}

这篇关于从网址快速加载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆