Update to use scale factor instead of that firstFrameOnly, since it's not used frequently as scale

This commit is contained in:
DreamPiggy 2018-04-13 02:34:52 +08:00
parent b9773d09c0
commit e829637a30
2 changed files with 10 additions and 8 deletions

View File

@ -13,7 +13,6 @@
#pragma mark - Decode
/**
Create and decode a image with the specify image data
If the image data is animated image format, create an animated image if possible
@param data The image data
@return The created image
@ -21,13 +20,13 @@
+ (nullable UIImage *)sd_imageWithData:(nullable NSData *)data;
/**
Create and decode a image with the specify image data
Create and decode a image with the specify image data and scale
@param data The image data
@param firstFrameOnly Even if the image data is animated image format, decode the first frame only
@param scale The image scale factor. Should be greater than or equal to 1.0.
@return The created image
*/
+ (nullable UIImage *)sd_imageWithData:(nullable NSData *)data firstFrameOnly:(BOOL)firstFrameOnly;
+ (nullable UIImage *)sd_imageWithData:(nullable NSData *)data scale:(CGFloat)scale;
#pragma mark - Encode
/**
@ -46,7 +45,7 @@
- (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat;
/**
Encode the current image to data with the specify image format
Encode the current image to data with the specify image format and compression quality
@param imageFormat The specify image format
@param compressionQuality The quality of the resulting image data. Value between 0.0-1.0. Some coders may not support compression quality.

View File

@ -12,14 +12,17 @@
@implementation UIImage (MultiFormat)
+ (nullable UIImage *)sd_imageWithData:(nullable NSData *)data {
return [self sd_imageWithData:data firstFrameOnly:NO];
return [self sd_imageWithData:data scale:1];
}
+ (nullable UIImage *)sd_imageWithData:(nullable NSData *)data firstFrameOnly:(BOOL)firstFrameOnly {
+ (nullable UIImage *)sd_imageWithData:(nullable NSData *)data scale:(CGFloat)scale {
if (!data) {
return nil;
}
SDWebImageCoderOptions *options = @{SDWebImageCoderDecodeFirstFrameOnly : @(firstFrameOnly)};
if (scale < 1) {
scale = 1;
}
SDWebImageCoderOptions *options = @{SDWebImageCoderDecodeScaleFactor : @(scale)};
return [[SDWebImageCodersManager sharedManager] decodedImageWithData:data options:options];
}