UIImage

@_spi(FW) extension UIImage

UIView+ImagePlugin

  • 根据名称从指定bundle加载UIImage,优先加载图片文件(无缓存),文件不存在时尝试系统imageNamed方式(有缓存)。支持设置图片解码选项

    Declaration

    Swift

    public static func fw_imageNamed(_ name: String, bundle: Bundle? = nil, options: [ImageCoderOptions : Any]? = nil) -> UIImage?
  • 从图片文件路径解码创建UIImage,自动识别scale,支持动图

    Declaration

    Swift

    public static func fw_image(contentsOfFile path: String) -> UIImage?
  • 从图片数据解码创建UIImage,默认scale为1,支持动图。支持设置图片解码选项

    Declaration

    Swift

    public static func fw_image(data: Data?, scale: CGFloat = 1, options: [ImageCoderOptions : Any]? = nil) -> UIImage?
  • 从UIImage编码创建图片数据,支持动图。支持设置图片编码选项

    Declaration

    Swift

    public static func fw_data(image: UIImage?, options: [ImageCoderOptions : Any]? = nil) -> Data?
  • 下载网络图片并返回下载凭据,指定option

    Declaration

    Swift

    @discardableResult
    public static func fw_downloadImage(_ url: URLParameter?, options: WebImageOptions = [], context: [ImageCoderOptions : Any]? = nil, completion: @escaping (UIImage?, Data?, Error?) -> Void, progress: ((Double) -> Void)? = nil) -> Any?
  • 指定下载凭据取消网络图片下载

    Declaration

    Swift

    public static func fw_cancelImageDownload(_ receipt: Any?)

UIImage+Theme

  • 获取当前主题样式对应静态图片用于显示,iOS13+可跟随系统改变

    Declaration

    Swift

    public var fw_image: UIImage? { get }
  • 指定主题样式获取对应静态图片用于显示,iOS13+可跟随系统改变

    Declaration

    Swift

    public func fw_image(forStyle style: ThemeStyle) -> UIImage?
  • 是否是主题图片,仅支持判断使用fwTheme创建的图片

    Declaration

    Swift

    public var fw_isThemeImage: Bool { get }

Color

  • 快速生成当前图片对应的默认主题图片

    Declaration

    Swift

    public var fw_themeImage: UIImage { get }
  • 指定主题颜色,快速生成当前图片对应的主题图片

    Declaration

    Swift

    public func fw_themeImage(color themeColor: UIColor) -> UIImage

Theme

  • 创建主题模拟动态图像,分别指定浅色和深色,不支持动态切换,需重新赋值才会变化

    Declaration

    Swift

    public static func fw_themeLight(_ light: UIImage?, dark: UIImage?) -> UIImage
  • 创建主题模拟动态图像,指定提供句柄,不支持动态切换,需重新赋值才会变化

    Declaration

    Swift

    public static func fw_themeImage(_ provider: @escaping (ThemeStyle) -> UIImage?) -> UIImage
  • 创建主题模拟动态图像,指定名称,兼容系统方式(仅iOS13+支持动态图像)和手工指定,支持动态切换,需配置any和dark

    Declaration

    Swift

    public static func fw_themeNamed(_ name: String) -> UIImage
  • 创建主题模拟动态图像,指定名称和bundle,兼容系统方式(仅iOS13+支持动态图像)和手工指定,支持动态切换,需配置any和dark

    Declaration

    Swift

    public static func fw_themeNamed(_ name: String, bundle: Bundle?) -> UIImage
  • 手工单个注册主题图像,未配置主题图像时可使用本方式

    Declaration

    Swift

    public static func fw_setThemeImage(_ image: UIImage?, forName name: String)
  • 手工批量注册主题图像,未配置主题图像时可使用本方式

    Declaration

    Swift

    public static func fw_setThemeImages(_ nameImages: [String : UIImage])

Color

  • 默认主题图片颜色,未设置时为浅色=>黑色,深色=>白色

    Declaration

    Swift

    public static var fw_themeImageColor: UIColor { get }
  • 默认主题图片颜色配置句柄,默认nil

    Declaration

    Swift

    public static var fw_themeImageColorConfiguration: (() -> UIColor)?

UIImage+AnimatedImage

  • 图片循环次数,静态图片始终是0,动态图片0代表无限循环

    Declaration

    Swift

    public var fw_imageLoopCount: UInt { get set }
  • 是否是动图,内部检查images数组

    Declaration

    Swift

    public var fw_isAnimated: Bool { get }
  • 是否是向量图,内部检查isSymbolImage属性,iOS11+支持PDF,iOS13+支持SVG

    Declaration

    Swift

    public var fw_isVector: Bool { get }
  • 获取图片原始数据格式,未指定时尝试从CGImage获取,获取失败返回ImageFormatUndefined

    Declaration

    Swift

    public var fw_imageFormat: ImageFormat { get set }

UIImage+Toolkit

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

    Declaration

    Swift

    public func fw_image(alpha: CGFloat) -> UIImage?
  • 从当前UIImage混合颜色创建UIImage,可自定义模式,默认destinationIn

    Declaration

    Swift

    public func fw_image(tintColor: UIColor, blendMode: CGBlendMode = .destinationIn) -> UIImage?
  • 缩放图片到指定大小

    Declaration

    Swift

    public func fw_image(scaleSize size: CGSize) -> UIImage?
  • 缩放图片到指定大小,指定模式

    Declaration

    Swift

    public func fw_image(scaleSize size: CGSize, contentMode: UIView.ContentMode) -> UIImage?
  • 按指定模式绘制图片

    Declaration

    Swift

    public func fw_draw(in rect: CGRect, contentMode: UIView.ContentMode, clipsToBounds: Bool)
  • 裁剪指定区域图片

    Declaration

    Swift

    public func fw_image(cropRect: CGRect) -> UIImage?
  • 指定颜色填充图片边缘

    Declaration

    Swift

    public func fw_image(insets: UIEdgeInsets, color: UIColor? = nil) -> UIImage?
  • 拉伸图片(平铺模式),指定端盖区域(不拉伸区域)

    Declaration

    Swift

    public func fw_image(capInsets: UIEdgeInsets) -> UIImage
  • 拉伸图片(指定模式),指定端盖区域(不拉伸区域)。Tile为平铺模式,Stretch为拉伸模式

    Declaration

    Swift

    public func fw_image(capInsets: UIEdgeInsets, resizingMode: UIImage.ResizingMode) -> UIImage
  • 生成圆角图片

    Declaration

    Swift

    public func fw_image(cornerRadius: CGFloat) -> UIImage?
  • 按角度常数(0~360)转动图片,指定图片尺寸是否延伸来适应内容,否则图片尺寸不变,内容被裁剪,默认true

    Declaration

    Swift

    public func fw_image(rotateDegree: CGFloat, fitSize: Bool = true) -> UIImage?
  • 生成mark图片

    Declaration

    Swift

    public func fw_image(maskImage: UIImage) -> UIImage?
  • 图片合并,并制定叠加图片的起始位置

    Declaration

    Swift

    public func fw_image(mergeImage: UIImage, atPoint: CGPoint) -> UIImage?
  • 图片应用CIFilter滤镜处理

    Declaration

    Swift

    public func fw_image(filter: CIFilter) -> UIImage?
  • 图片应用高斯模糊滤镜处理

    Declaration

    Swift

    public func fw_gaussianBlurImage(fuzzyValue: CGFloat = 10) -> UIImage?
  • 图片应用像素化滤镜处理

    Declaration

    Swift

    public func fw_pixellateImage(fuzzyValue: CGFloat = 10) -> UIImage?
  • 压缩图片到指定字节,图片太大时会改为JPG格式。不保证图片大小一定小于该大小

    Declaration

    Swift

    public func fw_compressImage(maxLength: Int, compressRatio: CGFloat = 0) -> UIImage?
  • 压缩图片到指定字节,图片太大时会改为JPG格式,可设置递减压缩率,默认0.3。不保证图片大小一定小于该大小

    Declaration

    Swift

    public func fw_compressData(maxLength: Int, compressRatio: CGFloat = 0) -> Data?
  • 长边压缩图片尺寸,获取等比例的图片

    Declaration

    Swift

    public func fw_compressImage(maxWidth: CGFloat) -> UIImage?
  • 通过指定图片最长边,获取等比例的图片size

    Declaration

    Swift

    public func fw_scaleSize(maxWidth: CGFloat) -> CGSize
  • 后台线程压缩图片,完成后主线程回调

    Declaration

    Swift

    public static func fw_compressImages(_ images: [UIImage], maxWidth: CGFloat, maxLength: Int, compressRatio: CGFloat = 0, completion: @escaping ([UIImage]) -> Void)
  • 后台线程压缩图片数据,完成后主线程回调

    Declaration

    Swift

    public static func fw_compressDatas(_ images: [UIImage], maxWidth: CGFloat, maxLength: Int, compressRatio: CGFloat = 0, completion: @escaping ([Data]) -> Void)
  • 获取原始渲染模式图片,始终显示原色,不显示tintColor。默认自动根据上下文

    Declaration

    Swift

    public var fw_originalImage: UIImage { get }
  • 获取模板渲染模式图片,始终显示tintColor,不显示原色。默认自动根据上下文

    Declaration

    Swift

    public var fw_templateImage: UIImage { get }
  • 判断图片是否有透明通道

    Declaration

    Swift

    public var fw_hasAlpha: Bool { get }
  • 获取当前图片的像素大小,多倍图会放大到一倍

    Declaration

    Swift

    public var fw_pixelSize: CGSize { get }
  • 从视图创建UIImage,生成截图,主线程调用

    Declaration

    Swift

    public static func fw_image(view: UIView) -> UIImage?
  • 从颜色创建UIImage,尺寸默认1x1

    Declaration

    Swift

    public static func fw_image(color: UIColor?) -> UIImage?
  • 从颜色创建UIImage,可指定尺寸和圆角,默认圆角0

    Declaration

    Swift

    public static func fw_image(color: UIColor?, size: CGSize, cornerRadius: CGFloat = 0) -> UIImage?
  • 从block创建UIImage,指定尺寸

    Declaration

    Swift

    public static func fw_image(size: CGSize, block: (CGContext) -> Void) -> UIImage?
  • 保存图片到相册,保存成功时error为nil

    Declaration

    Swift

    public func fw_saveImage(completion: ((Error?) -> Void)? = nil)
  • 保存视频到相册,保存成功时error为nil。如果视频地址为NSURL,需使用NSURL.path

    Declaration

    Swift

    public static func fw_saveVideo(_ videoPath: String, completion: ((Error?) -> Void)? = nil)
  • 获取灰度图

    Declaration

    Swift

    public var fw_grayImage: UIImage? { get }
  • 获取图片的平均颜色

    Declaration

    Swift

    public var fw_averageColor: UIColor? { get }
  • 倒影图片

    Declaration

    Swift

    public func fw_image(reflectScale: CGFloat) -> UIImage?
  • 倒影图片

    Declaration

    Swift

    public func fw_image(reflectScale: CGFloat, gap: CGFloat, alpha: CGFloat) -> UIImage?
  • 阴影图片

    Declaration

    Swift

    public func fw_image(shadowColor: UIColor, offset: CGSize, blur: CGFloat) -> UIImage?
  • 高斯模糊图片,默认模糊半径为10

    Declaration

    Swift

    public func fw_blurredImage(radius: CGFloat = 10) -> UIImage?
  • 图片裁剪,可指定frame、角度、圆形等

    Declaration

    Swift

    public func fw_croppedImage(frame: CGRect, angle: Int, circular: Bool) -> UIImage?
  • 如果没有透明通道,增加透明通道

    Declaration

    Swift

    public var fw_alphaImage: UIImage { get }
  • 截取View所有视图,包括旋转缩放效果

    Declaration

    Swift

    public static func fw_image(view: UIView, limitWidth: CGFloat) -> UIImage?
  • 获取AppIcon图片

    Declaration

    Swift

    public static func fw_appIconImage() -> UIImage?
  • 获取AppIcon指定尺寸图片,名称格式:AppIcon60x60

    Declaration

    Swift

    public static func fw_appIconImage(size: CGSize) -> UIImage?
  • 从Pdf数据或者路径创建指定大小UIImage

    Declaration

    Swift

    public static func fw_image(pdf path: Any, size: CGSize = .zero) -> UIImage?
  • 创建渐变颜色UIImage,支持四个方向,默认向下Down

    @param size 图片大小 @param colors 渐变颜色,CGColor数组,如:@[(bridge id)[UIColor redColor].CGColor, (bridge id)[UIColor blueColor].CGColor] @param locations 渐变位置,传NULL时均分,如:CGFloat locations[] = {0.0, 1.0}; @param direction 渐变方向,自动计算startPoint和endPoint,支持四个方向,默认向下Down @return 渐变颜色UIImage

    Declaration

    Swift

    public static func fw_gradientImage(size: CGSize, colors: [Any], locations: UnsafePointer<CGFloat>?, direction: UISwipeGestureRecognizer.Direction) -> UIImage?
  • 创建渐变颜色UIImage

    @param size 图片大小 @param colors 渐变颜色,CGColor数组,如:@[(bridge id)[UIColor redColor].CGColor, (bridge id)[UIColor blueColor].CGColor] @param locations 渐变位置,传NULL时均分,如:CGFloat locations[] = {0.0, 1.0}; @param startPoint 渐变开始点,需要根据rect计算 @param endPoint 渐变结束点,需要根据rect计算 @return 渐变颜色UIImage

    Declaration

    Swift

    public static func fw_gradientImage(size: CGSize, colors: [Any], locations: UnsafePointer<CGFloat>?, startPoint: CGPoint, endPoint: CGPoint) -> UIImage?