Added the helper convenient API `sd_isThumbnail`
Fix the metadata does not saved
This commit is contained in:
parent
03b46475eb
commit
bfa91a291b
|
@ -489,19 +489,10 @@ static id<SDImageLoader> _defaultImageLoader;
|
|||
shouldTransformImage = shouldTransformImage && (!originalImage.sd_isAnimated || (options & SDWebImageTransformAnimatedImage));
|
||||
shouldTransformImage = shouldTransformImage && (!originalImage.sd_isVector || (options & SDWebImageTransformVectorImage));
|
||||
// thumbnail check
|
||||
CGSize thumbnailSize = CGSizeZero;
|
||||
NSValue *thumbnailSizeValue = originalImage.sd_decodeOptions[SDImageCoderDecodeThumbnailPixelSize];
|
||||
if (thumbnailSizeValue != nil) {
|
||||
#if SD_MAC
|
||||
thumbnailSize = thumbnailSizeValue.sizeValue;
|
||||
#else
|
||||
thumbnailSize = thumbnailSizeValue.CGSizeValue;
|
||||
#endif
|
||||
}
|
||||
BOOL shouldEncodeThumbnail = thumbnailSize.width > 0 && thumbnailSize.height > 0;
|
||||
BOOL isThumbnail = originalImage.sd_isThumbnail;
|
||||
NSData *cacheData = originalData;
|
||||
UIImage *cacheImage = originalImage;
|
||||
if (shouldEncodeThumbnail) {
|
||||
if (isThumbnail) {
|
||||
cacheData = nil; // thumbnail don't store full size data
|
||||
originalImage = nil; // thumbnail don't have full size image
|
||||
}
|
||||
|
|
|
@ -71,6 +71,12 @@
|
|||
*/
|
||||
@property (nonatomic, assign) BOOL sd_isTransformed;
|
||||
|
||||
/**
|
||||
A bool value indicating that the image is using thumbnail decode with smaller size, so the image data may not always match original download one.
|
||||
@note This just check `sd_decodeOptions[.decodeThumbnailPixelSize] > CGSize.zero`
|
||||
*/
|
||||
@property (nonatomic, assign, readonly) BOOL sd_isThumbnail;
|
||||
|
||||
/**
|
||||
A dictionary value contains the decode options when decoded from SDWebImage loading system (say, `SDImageCacheDecodeImageData/SDImageLoaderDecode[Progressive]ImageData`)
|
||||
It may not always available and only image decoding related options will be saved. (including [.decodeScaleFactor, .decodeThumbnailPixelSize, .decodePreserveAspectRatio, .decodeFirstFrameOnly])
|
||||
|
|
|
@ -197,6 +197,19 @@
|
|||
objc_setAssociatedObject(self, @selector(sd_decodeOptions), sd_decodeOptions, OBJC_ASSOCIATION_COPY_NONATOMIC);
|
||||
}
|
||||
|
||||
-(BOOL)sd_isThumbnail {
|
||||
CGSize thumbnailSize = CGSizeZero;
|
||||
NSValue *thumbnailSizeValue = self.sd_decodeOptions[SDImageCoderDecodeThumbnailPixelSize];
|
||||
if (thumbnailSizeValue != nil) {
|
||||
#if SD_MAC
|
||||
thumbnailSize = thumbnailSizeValue.sizeValue;
|
||||
#else
|
||||
thumbnailSize = thumbnailSizeValue.CGSizeValue;
|
||||
#endif
|
||||
}
|
||||
return thumbnailSize.width > 0 && thumbnailSize.height > 0;
|
||||
}
|
||||
|
||||
- (SDImageCoderOptions *)sd_decodeOptions {
|
||||
SDImageCoderOptions *value = objc_getAssociatedObject(self, @selector(sd_decodeOptions));
|
||||
if ([value isKindOfClass:NSDictionary.class]) {
|
||||
|
|
|
@ -18,6 +18,7 @@ void SDImageCopyAssociatedObject(UIImage * _Nullable source, UIImage * _Nullable
|
|||
}
|
||||
// Image Metadata
|
||||
target.sd_isIncremental = source.sd_isIncremental;
|
||||
target.sd_isTransformed = source.sd_isTransformed;
|
||||
target.sd_decodeOptions = source.sd_decodeOptions;
|
||||
target.sd_imageLoopCount = source.sd_imageLoopCount;
|
||||
target.sd_imageFormat = source.sd_imageFormat;
|
||||
|
|
Loading…
Reference in New Issue