YYImage.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // YYImage.h
  3. // YYKit <https://github.com/ibireme/YYKit>
  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(<YYKit/YYKit.h>)
  13. #import <YYKit/YYAnimatedImageView.h>
  14. #import <YYKit/YYImageCoder.h>
  15. #else
  16. #import "YYAnimatedImageView.h"
  17. #import "YYImageCoder.h"
  18. #endif
  19. NS_ASSUME_NONNULL_BEGIN
  20. /**
  21. A YYImage object is a high-level way to display animated image data.
  22. @discussion It is a fully compatible `UIImage` subclass. It extends the UIImage
  23. to support animated WebP, APNG and GIF format image data decoding. It also
  24. support NSCoding protocol to archive and unarchive multi-frame image data.
  25. If the image is created from multi-frame image data, and you want to play the
  26. animation, try replace UIImageView with `YYAnimatedImageView`.
  27. Sample Code:
  28. // animation@3x.webp
  29. YYImage *image = [YYImage imageNamed:@"animation.webp"];
  30. YYAnimatedImageView *imageView = [YYAnimatedImageView alloc] initWithImage:image];
  31. [view addSubView:imageView];
  32. */
  33. @interface YYImage : UIImage <YYAnimatedImage>
  34. + (nullable YYImage *)imageNamed:(NSString *)name; // no cache!
  35. + (nullable YYImage *)imageWithContentsOfFile:(NSString *)path;
  36. + (nullable YYImage *)imageWithData:(NSData *)data;
  37. + (nullable YYImage *)imageWithData:(NSData *)data scale:(CGFloat)scale;
  38. /**
  39. If the image is created from data or file, then the value indicates the data type.
  40. */
  41. @property (nonatomic, readonly) YYImageType animatedImageType;
  42. /**
  43. If the image is created from animated image data (multi-frame GIF/APNG/WebP),
  44. this property stores the original image data.
  45. */
  46. @property (nullable, nonatomic, readonly) NSData *animatedImageData;
  47. /**
  48. The total memory usage (in bytes) if all frame images was loaded into memory.
  49. The value is 0 if the image is not created from a multi-frame image data.
  50. */
  51. @property (nonatomic, readonly) NSUInteger animatedImageMemorySize;
  52. /**
  53. Preload all frame image to memory.
  54. @discussion Set this property to `YES` will block the calling thread to decode
  55. all animation frame image to memory, set to `NO` will release the preloaded frames.
  56. If the image is shared by lots of image views (such as emoticon), preload all
  57. frames will reduce the CPU cost.
  58. See `animatedImageMemorySize` for memory cost.
  59. */
  60. @property (nonatomic) BOOL preloadAllAnimatedImageFrames;
  61. @end
  62. NS_ASSUME_NONNULL_END