酷店

YYImage.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // YYImage.h
  3. // YYImage <https://github.com/ibireme/YYImage>
  4. //
  5. // Created by ibireme on 14/10/20.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. #if __has_include(<YYImage/YYImage.h>)
  13. FOUNDATION_EXPORT double YYImageVersionNumber;
  14. FOUNDATION_EXPORT const unsigned char YYImageVersionString[];
  15. #import <YYImage/YYFrameImage.h>
  16. #import <YYImage/YYSpriteSheetImage.h>
  17. #import <YYImage/YYImageCoder.h>
  18. #import <YYImage/YYAnimatedImageView.h>
  19. #elif __has_include(<YYWebImage/YYImage.h>)
  20. #import <YYWebImage/YYFrameImage.h>
  21. #import <YYWebImage/YYSpriteSheetImage.h>
  22. #import <YYWebImage/YYImageCoder.h>
  23. #import <YYWebImage/YYAnimatedImageView.h>
  24. #else
  25. #import "YYFrameImage.h"
  26. #import "YYSpriteSheetImage.h"
  27. #import "YYImageCoder.h"
  28. #import "YYAnimatedImageView.h"
  29. #endif
  30. NS_ASSUME_NONNULL_BEGIN
  31. /**
  32. A YYImage object is a high-level way to display animated image data.
  33. @discussion It is a fully compatible `UIImage` subclass. It extends the UIImage
  34. to support animated WebP, APNG and GIF format image data decoding. It also
  35. support NSCoding protocol to archive and unarchive multi-frame image data.
  36. If the image is created from multi-frame image data, and you want to play the
  37. animation, try replace UIImageView with `YYAnimatedImageView`.
  38. Sample Code:
  39. // animation@3x.webp
  40. YYImage *image = [YYImage imageNamed:@"animation.webp"];
  41. YYAnimatedImageView *imageView = [YYAnimatedImageView alloc] initWithImage:image];
  42. [view addSubView:imageView];
  43. */
  44. @interface YYImage : UIImage <YYAnimatedImage>
  45. + (nullable YYImage *)imageNamed:(NSString *)name; // no cache!
  46. + (nullable YYImage *)imageWithContentsOfFile:(NSString *)path;
  47. + (nullable YYImage *)imageWithData:(NSData *)data;
  48. + (nullable YYImage *)imageWithData:(NSData *)data scale:(CGFloat)scale;
  49. /**
  50. If the image is created from data or file, then the value indicates the data type.
  51. */
  52. @property (nonatomic, readonly) YYImageType animatedImageType;
  53. /**
  54. If the image is created from animated image data (multi-frame GIF/APNG/WebP),
  55. this property stores the original image data.
  56. */
  57. @property (nullable, nonatomic, readonly) NSData *animatedImageData;
  58. /**
  59. The total memory usage (in bytes) if all frame images was loaded into memory.
  60. The value is 0 if the image is not created from a multi-frame image data.
  61. */
  62. @property (nonatomic, readonly) NSUInteger animatedImageMemorySize;
  63. /**
  64. Preload all frame image to memory.
  65. @discussion Set this property to `YES` will block the calling thread to decode
  66. all animation frame image to memory, set to `NO` will release the preloaded frames.
  67. If the image is shared by lots of image views (such as emoticon), preload all
  68. frames will reduce the CPU cost.
  69. See `animatedImageMemorySize` for memory cost.
  70. */
  71. @property (nonatomic) BOOL preloadAllAnimatedImageFrames;
  72. @end
  73. NS_ASSUME_NONNULL_END