YBImageBrowser icon indicating copy to clipboard operation
YBImageBrowser copied to clipboard

WEBP图片加载失败

Open 19aneng opened this issue 1 year ago • 3 comments

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

image

19aneng avatar Jul 30 '23 04:07 19aneng

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

19aneng avatar Jul 30 '23 04:07 19aneng

现在解决了吗?

YLbobo avatar Dec 13 '23 09:12 YLbobo

在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); }

fengshh93 avatar Jun 06 '24 09:06 fengshh93