YBImage.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // YBImage.h
  3. // YBImageBrowserDemo
  4. //
  5. // Created by 波儿菜 on 2018/8/31.
  6. // Copyright © 2018年 波儿菜. All rights reserved.
  7. //
  8. #if __has_include(<YYImage/YYImage.h>)
  9. #import <YYImage/YYFrameImage.h>
  10. #import <YYImage/YYSpriteSheetImage.h>
  11. #import <YYImage/YYImageCoder.h>
  12. #import <YYImage/YYAnimatedImageView.h>
  13. #elif __has_include(<YYWebImage/YYImage.h>)
  14. #import <YYWebImage/YYFrameImage.h>
  15. #import <YYWebImage/YYSpriteSheetImage.h>
  16. #import <YYWebImage/YYImageCoder.h>
  17. #import <YYWebImage/YYAnimatedImageView.h>
  18. #else
  19. #import "YYFrameImage.h"
  20. #import "YYSpriteSheetImage.h"
  21. #import "YYImageCoder.h"
  22. #import "YYAnimatedImageView.h"
  23. #endif
  24. NS_ASSUME_NONNULL_BEGIN
  25. /// 🙄波儿菜:Decide whether should to decode by image size. ('imageSize': physical pixel)
  26. typedef BOOL(^YBImageDecodeDecision)(CGSize imageSize, CGFloat scale);
  27. /**
  28. It is a fully compatible `UIImage` subclass. It extends the UIImage
  29. to support animated WebP, APNG and GIF format image data decoding. It also
  30. support NSCoding protocol to archive and unarchive multi-frame image data.
  31. If the image is created from multi-frame image data, and you want to play the
  32. animation, try replace UIImageView with `YYAnimatedImageView`.
  33. 🙄波儿菜:Copied from 'YYImage' and made some extensions.
  34. */
  35. @interface YBImage : UIImage <YYAnimatedImage>
  36. + (nullable __kindof UIImage *)imageNamed:(NSString *)name; // no cache!
  37. + (nullable YBImage *)imageWithContentsOfFile:(NSString *)path;
  38. + (nullable YBImage *)imageWithData:(NSData *)data;
  39. + (nullable YBImage *)imageWithData:(NSData *)data scale:(CGFloat)scale;
  40. /// 🙄波儿菜:Expand methodes.
  41. /// Start ->
  42. + (nullable __kindof UIImage *)imageNamed:(NSString *)name decodeDecision:(nullable YBImageDecodeDecision)decodeDecision;
  43. + (nullable YBImage *)imageWithContentsOfFile:(NSString *)path decodeDecision:(nullable YBImageDecodeDecision)decodeDecision;
  44. + (nullable YBImage *)imageWithData:(NSData *)data decodeDecision:(nullable YBImageDecodeDecision)decodeDecision;
  45. + (nullable YBImage *)imageWithData:(NSData *)data scale:(CGFloat)scale decodeDecision:(nullable YBImageDecodeDecision)decodeDecision;
  46. /// <- End
  47. /**
  48. If the image is created from data or file, then the value indicates the data type.
  49. */
  50. @property (nonatomic, readonly) YYImageType animatedImageType;
  51. /**
  52. If the image is created from animated image data (multi-frame GIF/APNG/WebP),
  53. this property stores the original image data.
  54. */
  55. @property (nullable, nonatomic, readonly) NSData *animatedImageData;
  56. /**
  57. The total memory usage (in bytes) if all frame images was loaded into memory.
  58. The value is 0 if the image is not created from a multi-frame image data.
  59. */
  60. @property (nonatomic, readonly) NSUInteger animatedImageMemorySize;
  61. /**
  62. Preload all frame image to memory.
  63. @discussion Set this property to `YES` will block the calling thread to decode
  64. all animation frame image to memory, set to `NO` will release the preloaded frames.
  65. If the image is shared by lots of image views (such as emoticon), preload all
  66. frames will reduce the CPU cost.
  67. See `animatedImageMemorySize` for memory cost.
  68. */
  69. @property (nonatomic) BOOL preloadAllAnimatedImageFrames;
  70. @end
  71. NS_ASSUME_NONNULL_END