如何使用 SDWebImage 在 iOS 中设置渐进图像?
How to set progressive image in iOS using SDWebImage?
我尝试在我的应用程序中逐步加载图像。基本上我尝试的是在加载图像时,我想从模糊状态显示完全加载的图像。我试过了,
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:[NSURL URLWithString:@"https://profile.microsoft.com/RegsysProfileCenter/Images/personal_info.jpg"]
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
[self.profileBtn setImage:[UIImage imageWithData:[NSData dataWithBytes:&receivedSize length:sizeof(receivedSize)] scale:15] forState:UIControlStateNormal];
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (image) {
// [self.profileBtn setImage:image forState:UIControlStateNormal];
}
}];
是否可以使用 SDWebImage 逐步加载图像。请帮我解决这个问题。
您可以在临时标签或 activity 指示器下方显示下载百分比(可以在图像视图或按钮上显示 activity 指示器,直到下载未完成)如进度块,
NSInteger downloadCompleted = (receivedSize/ expectedSize) * 100;
label.text = downloadCompleted; //temp label on image view or below activityindicator
希望这会有所帮助:)
你可以试试这个实现
+ (void)loadImageWithURLString:(NSString *)urlString forImageView:(UIImageView *)imageView {
[imageView sd_setImageWithURL:[Utilities stringToURL:urlString]
placeholderImage:[UIImage placeHolderImage]
options:SDWebImageProgressiveDownload];
}
选项说
/**
* This flag enables progressive download, the image is displayed progressively during download as a browser would do.
* By default, the image is only displayed once completely downloaded.
*/
SDWebImageProgressiveDownload = 1 << 3,
我尝试在我的应用程序中逐步加载图像。基本上我尝试的是在加载图像时,我想从模糊状态显示完全加载的图像。我试过了,
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:[NSURL URLWithString:@"https://profile.microsoft.com/RegsysProfileCenter/Images/personal_info.jpg"]
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
[self.profileBtn setImage:[UIImage imageWithData:[NSData dataWithBytes:&receivedSize length:sizeof(receivedSize)] scale:15] forState:UIControlStateNormal];
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
if (image) {
// [self.profileBtn setImage:image forState:UIControlStateNormal];
}
}];
是否可以使用 SDWebImage 逐步加载图像。请帮我解决这个问题。
您可以在临时标签或 activity 指示器下方显示下载百分比(可以在图像视图或按钮上显示 activity 指示器,直到下载未完成)如进度块,
NSInteger downloadCompleted = (receivedSize/ expectedSize) * 100;
label.text = downloadCompleted; //temp label on image view or below activityindicator
希望这会有所帮助:)
你可以试试这个实现
+ (void)loadImageWithURLString:(NSString *)urlString forImageView:(UIImageView *)imageView {
[imageView sd_setImageWithURL:[Utilities stringToURL:urlString]
placeholderImage:[UIImage placeHolderImage]
options:SDWebImageProgressiveDownload];
}
选项说
/**
* This flag enables progressive download, the image is displayed progressively during download as a browser would do.
* By default, the image is only displayed once completely downloaded.
*/
SDWebImageProgressiveDownload = 1 << 3,