Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于wepP图片不能显示,并把SDWebImage版本升级到4.7.0 #358

Open
fengshh93 opened this issue Jun 6, 2024 · 0 comments
Open

Comments

@fengshh93
Copy link

在YBIBDefaultWebImageMediator.m头部导入#import "UIImage+MultiFormat.h"
把方法yb_downloadImageWithURL修改一下

(id)yb_downloadImageWithURL:(NSURL *)URL requestModifier:(nullable YBIBWebImageRequestModifierBlock)requestModifier progress:(nonnull YBIBWebImageProgressBlock)progress success:(nonnull YBIBWebImageSuccessBlock)success failed:(nonnull YBIBWebImageFailedBlock)failed {
if (!URL) return nil;

SDWebImageDownloadToken *token = [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:URL options:SDWebImageDownloaderLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
if (progress) progress(receivedSize, expectedSize);
} completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {

if (error) {
if (failed) failed(error, finished);
} else {
SDImageFormat imgFType= [NSData sd_imageFormatForImageData:data];
if (imgFType == SDImageFormatUndefined || imgFType == SDImageFormatWebP) {//处理webP图片不能显示的情况
data = UIImageJPEGRepresentation(image, 1);
}
if (success) success(data, finished);
}
}];
return token;

}

主要是webp图片请求成功,但是YBIBImageData 的loadURL_download方法转换失败导致
所以在yb_downloadImageWithURL添加了webP图片的处理代码
SDImageFormat imgFType= [NSData sd_imageFormatForImageData:data];
if (imgFType == SDImageFormatUndefined || imgFType == SDImageFormatWebP) {//处理webP图片不能显示的情况
data = UIImageJPEGRepresentation(image, 1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant