UIImage(FWToolkit)

@interface UIImage (FWToolkit)

/// 从当前图片创建指定透明度的图片
- (nullable UIImage *)fw_imageWithAlpha:(CGFloat)alpha NS_REFINED_FOR_SWIFT;

/// 从当前图片混合颜色创建UIImage,默认kCGBlendModeDestinationIn模式,适合透明图标
- (nullable UIImage *)fw_imageWithTintColor:(UIColor *)tintColor NS_REFINED_FOR_SWIFT;

/// 从当前UIImage混合颜色创建UIImage,自定义模式
- (nullable UIImage *)fw_imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode NS_REFINED_FOR_SWIFT;

/// 缩放图片到指定大小
- (nullable UIImage *)fw_imageWithScaleSize:(CGSize)size NS_REFINED_FOR_SWIFT;

/// 缩放图片到指定大小,指定模式
- (nullable UIImage *)fw_imageWithScaleSize:(CGSize)size contentMode:(UIViewContentMode)contentMode NS_REFINED_FOR_SWIFT;

/// 按指定模式绘制图片
- (void)fw_drawInRect:(CGRect)rect withContentMode:(UIViewContentMode)contentMode clipsToBounds:(BOOL)clipsToBounds NS_REFINED_FOR_SWIFT;

/// 裁剪指定区域图片
- (nullable UIImage *)fw_imageWithCropRect:(CGRect)rect NS_REFINED_FOR_SWIFT;

/// 指定颜色填充图片边缘
- (nullable UIImage *)fw_imageWithInsets:(UIEdgeInsets)insets color:(nullable UIColor *)color NS_REFINED_FOR_SWIFT;

/// 拉伸图片(平铺模式),指定端盖区域(不拉伸区域)
- (UIImage *)fw_imageWithCapInsets:(UIEdgeInsets)insets NS_REFINED_FOR_SWIFT;

/// 拉伸图片(指定模式),指定端盖区域(不拉伸区域)。Tile为平铺模式,Stretch为拉伸模式
- (UIImage *)fw_imageWithCapInsets:(UIEdgeInsets)insets resizingMode:(UIImageResizingMode)resizingMode NS_REFINED_FOR_SWIFT;

/// 生成圆角图片
- (nullable UIImage *)fw_imageWithCornerRadius:(CGFloat)radius NS_REFINED_FOR_SWIFT;

/// 按角度常数(0~360)转动图片,默认图片尺寸适应内容
- (nullable UIImage *)fw_imageWithRotateDegree:(CGFloat)degree NS_REFINED_FOR_SWIFT;

/// 按角度常数(0~360)转动图片,指定图片尺寸是否延伸来适应内容,否则图片尺寸不变,内容被裁剪
- (nullable UIImage *)fw_imageWithRotateDegree:(CGFloat)degree fitSize:(BOOL)fitSize NS_REFINED_FOR_SWIFT;

/// 生成mark图片
- (nullable UIImage *)fw_imageWithMaskImage:(UIImage *)maskImage NS_REFINED_FOR_SWIFT;

/// 图片合并,并制定叠加图片的起始位置
- (nullable UIImage *)fw_imageWithMergeImage:(UIImage *)image atPoint:(CGPoint)point NS_REFINED_FOR_SWIFT;

/// 图片应用CIFilter滤镜处理
- (nullable UIImage *)fw_imageWithFilter:(CIFilter *)filter NS_REFINED_FOR_SWIFT;

/// 压缩图片到指定字节,图片太大时会改为JPG格式。不保证图片大小一定小于该大小
- (nullable UIImage *)fw_compressImageWithMaxLength:(NSInteger)maxLength NS_REFINED_FOR_SWIFT;

/// 压缩图片到指定字节,图片太大时会改为JPG格式,可设置递减压缩率,默认0.1。不保证图片大小一定小于该大小
- (nullable NSData *)fw_compressDataWithMaxLength:(NSInteger)maxLength compressRatio:(CGFloat)compressRatio NS_REFINED_FOR_SWIFT;

/// 长边压缩图片尺寸,获取等比例的图片
- (nullable UIImage *)fw_compressImageWithMaxWidth:(NSInteger)maxWidth NS_REFINED_FOR_SWIFT;

/// 通过指定图片最长边,获取等比例的图片size
- (CGSize)fw_scaleSizeWithMaxWidth:(CGFloat)maxWidth NS_REFINED_FOR_SWIFT;

/// 获取原始渲染模式图片,始终显示原色,不显示tintColor。默认自动根据上下文
@property (nonatomic, readonly) UIImage *fw_originalImage NS_REFINED_FOR_SWIFT;

/// 获取模板渲染模式图片,始终显示tintColor,不显示原色。默认自动根据上下文
@property (nonatomic, readonly) UIImage *fw_templateImage NS_REFINED_FOR_SWIFT;

/// 判断图片是否有透明通道
@property (nonatomic, assign, readonly) BOOL fw_hasAlpha NS_REFINED_FOR_SWIFT;

/// 获取当前图片的像素大小,多倍图会放大到一倍
@property (nonatomic, assign, readonly) CGSize fw_pixelSize NS_REFINED_FOR_SWIFT;

/// 从视图创建UIImage,生成截图,主线程调用
+ (nullable UIImage *)fw_imageWithView:(UIView *)view NS_REFINED_FOR_SWIFT;

/// 从颜色创建UIImage,默认尺寸1x1
+ (nullable UIImage *)fw_imageWithColor:(UIColor *)color NS_REFINED_FOR_SWIFT;

/// 从颜色创建UIImage,指定尺寸
+ (nullable UIImage *)fw_imageWithColor:(UIColor *)color size:(CGSize)size NS_REFINED_FOR_SWIFT;

/// 从颜色创建UIImage,指定尺寸和圆角
+ (nullable UIImage *)fw_imageWithColor:(UIColor *)color size:(CGSize)size cornerRadius:(CGFloat)radius NS_REFINED_FOR_SWIFT;

/// 从block创建UIImage,指定尺寸
+ (nullable UIImage *)fw_imageWithSize:(CGSize)size block:(void (NS_NOESCAPE ^)(CGContextRef context))block NS_REFINED_FOR_SWIFT;

/// 保存图片到相册,保存成功时error为nil
- (void)fw_saveImageWithCompletion:(nullable void (^)(NSError * _Nullable error))completion NS_SWIFT_NAME(__fw_saveImage(completion:)) NS_REFINED_FOR_SWIFT;

// 保存视频到相册,保存成功时error为nil。如果视频地址为NSURL,需使用NSURL.path
+ (void)fw_saveVideo:(NSString *)videoPath withCompletion:(nullable void (^)(NSError * _Nullable error))completion NS_REFINED_FOR_SWIFT;

@end

Undocumented

  • 从当前图片创建指定透明度的图片

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithAlpha:(CGFloat)alpha;
  • 从当前图片混合颜色创建UIImage,默认kCGBlendModeDestinationIn模式,适合透明图标

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithTintColor:(nonnull UIColor *)tintColor;
  • 从当前UIImage混合颜色创建UIImage,自定义模式

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithTintColor:(nonnull UIColor *)tintColor
                                      blendMode:(CGBlendMode)blendMode;
  • 缩放图片到指定大小

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithScaleSize:(CGSize)size;
  • 缩放图片到指定大小,指定模式

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithScaleSize:(CGSize)size
                                    contentMode:(UIViewContentMode)contentMode;
  • 按指定模式绘制图片

    Declaration

    Objective-C

    - (void)fw_drawInRect:(CGRect)rect
          withContentMode:(UIViewContentMode)contentMode
            clipsToBounds:(BOOL)clipsToBounds;
  • 裁剪指定区域图片

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithCropRect:(CGRect)rect;
  • 指定颜色填充图片边缘

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithInsets:(UIEdgeInsets)insets
                                       color:(nullable UIColor *)color;
  • 拉伸图片(平铺模式),指定端盖区域(不拉伸区域)

    Declaration

    Objective-C

    - (nonnull UIImage *)fw_imageWithCapInsets:(UIEdgeInsets)insets;
  • 拉伸图片(指定模式),指定端盖区域(不拉伸区域)。Tile为平铺模式,Stretch为拉伸模式

    Declaration

    Objective-C

    - (nonnull UIImage *)fw_imageWithCapInsets:(UIEdgeInsets)insets
                                  resizingMode:(UIImageResizingMode)resizingMode;
  • 生成圆角图片

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithCornerRadius:(CGFloat)radius;
  • 按角度常数(0~360)转动图片,默认图片尺寸适应内容

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithRotateDegree:(CGFloat)degree;
  • 按角度常数(0~360)转动图片,指定图片尺寸是否延伸来适应内容,否则图片尺寸不变,内容被裁剪

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithRotateDegree:(CGFloat)degree
                                           fitSize:(BOOL)fitSize;
  • 生成mark图片

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithMaskImage:(nonnull UIImage *)maskImage;
  • 图片合并,并制定叠加图片的起始位置

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithMergeImage:(nonnull UIImage *)image
                                         atPoint:(CGPoint)point;
  • 图片应用CIFilter滤镜处理

    Declaration

    Objective-C

    - (nullable UIImage *)fw_imageWithFilter:(nonnull CIFilter *)filter;
  • 压缩图片到指定字节,图片太大时会改为JPG格式。不保证图片大小一定小于该大小

    Declaration

    Objective-C

    - (nullable UIImage *)fw_compressImageWithMaxLength:(NSInteger)maxLength;
  • 压缩图片到指定字节,图片太大时会改为JPG格式,可设置递减压缩率,默认0.1。不保证图片大小一定小于该大小

    Declaration

    Objective-C

    - (nullable NSData *)fw_compressDataWithMaxLength:(NSInteger)maxLength
                                        compressRatio:(CGFloat)compressRatio;
  • 长边压缩图片尺寸,获取等比例的图片

    Declaration

    Objective-C

    - (nullable UIImage *)fw_compressImageWithMaxWidth:(NSInteger)maxWidth;
  • 通过指定图片最长边,获取等比例的图片size

    Declaration

    Objective-C

    - (CGSize)fw_scaleSizeWithMaxWidth:(CGFloat)maxWidth;
  • 获取原始渲染模式图片,始终显示原色,不显示tintColor。默认自动根据上下文

    Declaration

    Objective-C

    @property (nonatomic, readonly) NS_REFINED_FOR_SWIFT UIImage *fw_originalImage;
  • 获取模板渲染模式图片,始终显示tintColor,不显示原色。默认自动根据上下文

    Declaration

    Objective-C

    @property (nonatomic, readonly) NS_REFINED_FOR_SWIFT UIImage *fw_templateImage;
  • 判断图片是否有透明通道

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL fw_hasAlpha;
  • 获取当前图片的像素大小,多倍图会放大到一倍

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGSize fw_pixelSize;
  • 从视图创建UIImage,生成截图,主线程调用

    Declaration

    Objective-C

    + (nullable UIImage *)fw_imageWithView:(nonnull UIView *)view;
  • 从颜色创建UIImage,默认尺寸1x1

    Declaration

    Objective-C

    + (nullable UIImage *)fw_imageWithColor:(nonnull UIColor *)color;
  • 从颜色创建UIImage,指定尺寸

    Declaration

    Objective-C

    + (nullable UIImage *)fw_imageWithColor:(nonnull UIColor *)color
                                       size:(CGSize)size;
  • 从颜色创建UIImage,指定尺寸和圆角

    Declaration

    Objective-C

    + (nullable UIImage *)fw_imageWithColor:(nonnull UIColor *)color
                                       size:(CGSize)size
                               cornerRadius:(CGFloat)radius;
  • 从block创建UIImage,指定尺寸

    Declaration

    Objective-C

    + (nullable UIImage *)fw_imageWithSize:(CGSize)size
                                     block:(nonnull void (^)(CGContextRef _Nonnull))
                                               block;
  • 保存图片到相册,保存成功时error为nil

    Declaration

    Objective-C

    - (void)fw_saveImageWithCompletion:
        (nullable void (^)(NSError *_Nullable __strong))completion;
  • Undocumented

    Declaration

    Objective-C

    + (void)fw_saveVideo:(NSString *)videoPath withCompletion:(nullable void (^)(NSError * _Nullable error))completion NS_REFINED_FOR_SWIFT;