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

WEBP图片加载失败 #350

Open
19aneng opened this issue Jul 30, 2023 · 3 comments
Open

WEBP图片加载失败 #350

19aneng opened this issue Jul 30, 2023 · 3 comments

Comments

@19aneng
Copy link

19aneng commented Jul 30, 2023

图片路由: https://storage.googleapis.com/find_art/dev/gallery/image/202307/26/PQrOrXOdC9Z9kiZMo2v4nqlbveXILo2LEer8Muzm.webp

image

@19aneng
Copy link
Author

19aneng commented Jul 30, 2023

能不能把YYImage加载换成SD加载,YY没人维护了,...

@YLbobo
Copy link

YLbobo commented Dec 13, 2023

现在解决了吗?

@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

3 participants