Framework

KLAdaptivePalette

KLAdaptivePalette analyzes the visible part of an image and returns colors that can be used for a surface, text, tint, or accent. The analyzer works on a bounded raster instead of the original pixel dimensions. This keeps the cost predictable for photos and large media. The analysis is aware of the host container. A request can describe .aspectFill or .aspectFit rendering and an anchor point, so the result is based on the pixels the user is likely to see rather than an unrelated corner of the source image.

Overview

let request = KLPaletteRequest(
    image: image,
    cacheID: mediaID,
    containerSize: size,
    contentMode: .aspectFill,
    anchor: CGPoint(x: 0.5, y: 0.5)
)
let palette = KLPaletteAnalyzer().analyze(request)
let background = palette.lightBackground
let foreground = palette.lightForeground

Guides

KLAdaptivePalette · Swift Package documentation