You need to enable JavaScript to run this app.
veImageX

veImageX

复制全文
iOS 加载 SDK
SDWebImage 接口适配说明
复制全文
SDWebImage 接口适配说明

为了方便客户更友好的接入 BDwebimage 图片加载 SDK,使用高效的图片解码加载等能力,我们提供了针对 SDwebimage 等开源图片库的接口兼容能力。以下为 SDwebimage 适配文档,您可以参考以下内容完成具体接口调用。

适配说明

下载、缓存、预加载等功能与原 SDWebImage 的区别在于调用方法的对象不同,将原 SDWebImage 的调用对象替换为[SDInterface sharedInterface] ,以及方法名前缀从sd_xxx 换成sdi_xxx

目前不包括针对 transform 部分的适配,但您可以直接对返回的图片使用 BDWebImage 进行 transform 处理。

  • url:与 SDWebImage 兼容。

  • option:传入 BDwebimage 的选项常量,详细内容可以参见BDWebImageRequest.h

  • Progress block:与 SDWebImage 兼容,可以在图片加载后做某些操作。

  • Completed block:与 SDWebImage 兼容。

SDWebImage 接口兼容

在调用 SDWebImage 的接口时需要引入头文件,代码如下所示:

#import <UIImageView+SDInterface.h>

通过 UIImageView 加载图片

将原sd_setImageWithURL替换成sdi_setImageWithURL

// SDWebImage 原始接口获取图片
[self.demoImageView sd_setImageWithURL:[NSURL URLWithString:url] 
                      placeholderImage:nil 
                               options:0 
                             completed:^(UIImage * _Nullable image, NSError * _Nullable error, BDImageCacheType cacheType, NSURL * _Nullable imageURL) {
      NSLog(@"complete");
}];
 
// BDWebImage 兼容接口获取图片
[self.demoImageView sdi_setImageWithURL:[NSURL URLWithString:url] 
                       placeholderImage:nil 
                                options:0 
                              completed:^(UIImage * _Nullable image, NSError * _Nullable error, BDImageCacheType cacheType, NSURL * _Nullable imageURL) {
      NSLog(@"complete");
}];

通过 manager 管理图片

对图片进行管理的中转站,记录哪些图片正在读取。

// SDwebimage 原始接口管理图片
[[SDWebImageManager sharedManager] loadImageWithURL:imageURL
                                            options:0
                                           progress:^(NSInteger receivedSize, NSInteger expectedSize) {
            // progression tracking code
         }
                                          completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
          if (image) {
            // do something with image
          }
}];
// BDwebimage 兼容接口管理图片
[[SDInterface sharedInterface] loadImageWithURL:[NSURL URLWithString:url]
                      options:0
                      progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
      // progression tracking code
    }
                     completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
      // do something with image
    }];

通过 Downloader 下载图片

根据 URL 向网络读取数据(实现部分读取和全部读取后再通知回调两种方式),该操作对下载成功后的图片资源不会自动缓存。

// SDwebimage  原始接口下载图片
 [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:imageURL
                             options:0
                             progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
         // progression with image
   }
                            completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
        // do something with image
  }];
 
 // BDwebimage 兼容接口下载图片
[[SDInterface sharedInterface] downloadImageWithURL:[NSURL URLWithString:url]
                        options:0
                        progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
      // progression tracking code
    }
                       completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
      // do something with image
    }];

通过 Prefetcher 预加载图片

可以预先下载图片,方便后续使用。

// SDwebimage  原始接口预下载图片
[[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:imageURLs2 
                                                  progress:^(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls) {
        // progression tracking code 
      } 
                                                 completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
        // do something with image
      }];
      
// BDwebimage  兼容接口预下载图片
[[SDInterface sharedInterface] prefetchURLs:url 
                                   progress:^(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls) {
      // progression tracking code 
    } 
                                  completed:^(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls) {
      // do something with image
    }];

通过 Cache 异步缓存

对图片进行存储和读取(可实现存在内存中或者存在硬盘上两种方式) 实现图片和内存清理工作。

// SDwebimage 原始接口异步缓存
[[SDImageCache sharedImageCache] storeImage:image forKey:kTestImageKeyJPEG toDisk:YES completion:nil];
// BDwebimage 兼容接口异步缓存
[[SDInterface sharedInterface] storeImage:image forKey:kTestImageKeyJPEG toDisk:YES completion:nil];

Transform

如果用户需要使用 transform 操作可以参考下面设置,设置圆角半径的 demo 示例如下所示:

[[SDInterface sharedInterface] loadImageWithURL:[NSURL URLWithString:url] 
                                        options:0 
                                       progress:nil 
                                      completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
    image = [image bd_imageByRoundCornerRadius:100];
    [self.demoImageView setImage:image];
  }];

同时您还可以自定义 transform 操作,直接继承 BDBaseTransformer 类即可。

BDWebImage 中还提供了基础变换的子库,详细方法可以参见 UIImage+BDImageTransform.h

进阶特性功能

边下边播

BDWebImage 具有边下边播的特性,有以下两种设置方式:

  1. 通过设置optionBDImageAnimatedImageProgressiveDownload,示例如下:
// SDInterface
[[SDInterface sharedInterface] loadImageWithURL:[NSURL URLWithString:url]
                                        options:BDImageAnimatedImageProgressiveDownload
                                       progress:nil
                                      completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
    [self.demoImageView setImage:image];
}];
  1. 使用BDImageView方法,示例如下:
UIImageView * demoImageView = [BDImageView new];
// UIImageView
[demoImageView sdi_setImageWithURL:[NSURL URLWithString:url] 
                       placeholderImage:nil 
                                options:BDImageAnimatedImageProgressiveDownload];

具有 alpha 通道的 HEIC 图片

BDWebImage 使用 veImageX 自研的 HEIC 解码库能够支持 alpha 通道图片的解码,目前系统的解码接口不支持对带 alpha 通道的 HEIC 图片进行解码。

使用高效的网络优化库 TTNet

TTNet 是字节跳动通用的网络请求封装框架,用来向服务端发起请求,具有以下特点:

说明

TTNet 为增值产品功能,具体产品介绍和计费详情请联系您的商务经理。

  • 支持 quic 以及 hps 等多协议;

  • 链接复用、连接池、连接探测;

  • 稳定性、灵活性、健壮性、单线程模型;

  • 预链接、链接保活、复合链接、dns反劫持等。

最近更新时间:2023.10.17 11:56:45
这个页面对您有帮助吗?
有用
有用
无用
无用