YYImage.h 2.8 KB

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