YYImage.h 2.6 KB

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