如何改善 UIImage 加载的加载时间?
How can I improve loading time for UIImage loading?
这是我到目前为止完成的代码:
[userpic sd_setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"blackSquare.png"] options:SDWebImageProgressiveDownload];
在我的代码下面,我觉得有点快。检查一个。我正在使用 Afnetwork
#import "UIImageView+AFNetworking.h"
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large",[[NSUSER objectForKey:@"user_info"] objectForKey:@"id"]]];
UIImage *pImage=[UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
_prof_pic_imageview.image=pImage;
我建议改用 SDWebImage。@S.Karthik 的方法很好,但会消耗更多内存,并会在您的应用程序中造成视图延迟。
SDWebImage 与@karthik 编写的完全相同,但也使用缓存,因此您不需要在显示时每次都获取图像。
试试这个
[userpic sd_setImageWithURL:[URLWithString:imageURL placeholderImage:[UIImage imageNamed:@"blackSquare.png"]]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//Image done
}];
这是我到目前为止完成的代码:
[userpic sd_setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:[UIImage imageNamed:@"blackSquare.png"] options:SDWebImageProgressiveDownload];
在我的代码下面,我觉得有点快。检查一个。我正在使用 Afnetwork
#import "UIImageView+AFNetworking.h"
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large",[[NSUSER objectForKey:@"user_info"] objectForKey:@"id"]]];
UIImage *pImage=[UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
_prof_pic_imageview.image=pImage;
我建议改用 SDWebImage。@S.Karthik 的方法很好,但会消耗更多内存,并会在您的应用程序中造成视图延迟。 SDWebImage 与@karthik 编写的完全相同,但也使用缓存,因此您不需要在显示时每次都获取图像。
试试这个
[userpic sd_setImageWithURL:[URLWithString:imageURL placeholderImage:[UIImage imageNamed:@"blackSquare.png"]]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//Image done
}];