diff --git a/SDWebImage/UIImage+MultiFormat.h b/SDWebImage/UIImage+MultiFormat.h index c66ae83c..ff4b9ee8 100644 --- a/SDWebImage/UIImage+MultiFormat.h +++ b/SDWebImage/UIImage+MultiFormat.h @@ -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. diff --git a/SDWebImage/UIImage+MultiFormat.m b/SDWebImage/UIImage+MultiFormat.m index 846bd167..b0145bc8 100644 --- a/SDWebImage/UIImage+MultiFormat.m +++ b/SDWebImage/UIImage+MultiFormat.m @@ -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]; }