SLImageDecoder.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // SLImageDecoder.h
  3. // WSLImageView
  4. //
  5. // Created by 王双龙 on 2018/10/26.
  6. // Copyright © 2018年 https://www.jianshu.com/u/e15d1f644bea. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. NS_ASSUME_NONNULL_BEGIN
  11. //存储每一帧图片信息的对象
  12. @interface SLImageFrame : NSObject
  13. @property (nonatomic, assign) NSUInteger index; //索引
  14. @property (nonatomic, assign) CGFloat width; //每一帧的图像宽 像素
  15. @property (nonatomic, assign) CGFloat height; //每一帧的图像高 像素
  16. @property (nonatomic, assign) NSUInteger offsetX; // 每一帧在画布上的偏移量X (left-bottom based)
  17. @property (nonatomic, assign) NSUInteger offsetY; // 每一帧在画布上的偏移量Y (left-bottom based)
  18. @property (nonatomic, assign) NSTimeInterval duration; //持续时长
  19. @property (nonatomic, assign) UIImageOrientation imageOrientation; //图像方向
  20. @property (nullable, nonatomic, strong) UIImage *image; //解码后的image
  21. @end
  22. /**
  23. 图片类型
  24. */
  25. typedef NS_ENUM(NSUInteger, SLImageType) {
  26. SLImageTypeUnknown = 0, ///< unknown
  27. SLImageTypeJPEG, ///< jpeg, jpg
  28. SLImageTypeJPEG2000, ///< jp2
  29. SLImageTypeTIFF, ///< tiff, tif
  30. SLImageTypeBMP, ///< bmp
  31. SLImageTypeICO, ///< ico
  32. SLImageTypeICNS, ///< icns
  33. SLImageTypeGIF, ///< gif
  34. SLImageTypePNG, ///< png
  35. SLImageTypeWebP, ///< webp
  36. SLImageTypeOther, ///< other image format
  37. };
  38. /**
  39. 图片解码工具
  40. */
  41. @interface SLImageDecoder : NSObject
  42. /**
  43. 解码的数据
  44. */
  45. @property (nullable, nonatomic, readonly) NSData *data;
  46. /**
  47. 图像比例系数
  48. */
  49. @property (nonatomic, assign) CGFloat scale;
  50. /**
  51. 图片类型
  52. */
  53. @property (nonatomic, assign, readonly) SLImageType imageType;
  54. /**
  55. 图像帧总个数
  56. */
  57. @property (nonatomic, assign, readonly) NSInteger frameCount;
  58. /**
  59. 循环次数
  60. */
  61. @property (nonatomic, assign, readonly) NSInteger loopCount;
  62. /**
  63. 循环一次的时长
  64. */
  65. @property (nonatomic, assign) NSTimeInterval totalTime;
  66. /**
  67. 画布的大小 宽*高
  68. */
  69. @property (nonatomic, readonly) CGSize canvasSize;
  70. /**
  71. 配置图片解码器
  72. @param data 图片数据
  73. @param scale 图像比例系数 一般情况下为[UIScreen mainScreen].scale]
  74. */
  75. - (void)decoderWithData:(NSData *)data scale:(CGFloat)scale;
  76. /**
  77. 获取某一帧的图片信息:索引、持续时长、宽高、方向、解码后的image
  78. index >= 0
  79. */
  80. - (SLImageFrame *)imageFrameAtIndex:(NSInteger)index;
  81. /**
  82. 获取解码后的第index帧image
  83. */
  84. - (UIImage *)imageAtIndex:(NSInteger)index;
  85. /**
  86. 某一帧持续时长
  87. */
  88. - (NSTimeInterval)imageDurationAtIndex:(NSUInteger)index;
  89. @end
  90. NS_ASSUME_NONNULL_END