Skip to content

useImageMode

@astryxdesign/core v0.7.1 · useImageMode

参数 ​

名称类型默认值说明
srcMaybeRefOrGetter<string | null | undefined>—要分析的图片地址。普通字符串、ref、getter 都行。为 null 或 undefined 时直接给 fallback。必填。
optionsMaybeRefOrGetter<UseImageModeOptions>{}分析的可选配置。每次分析时重新读,写成 getter 就能一直取到最新值。
options.regionImageSampleRegion整张图只采这一块。坐标都按 0 到 1 的比例给出:{ x, y, width, height }。
options.thresholdnumber0.5分深浅的亮度阈值。低于算暗,高于算亮。
options.fallback'dark' | 'light' | nullnull还在加载,或者读图失败时返回的值。

返回值 ​

名称类型说明
modeRef<'dark' | 'light' | null>图片的深浅。还在加载时是 null,src 为空时是 fallback。

分析的两段也一起导出了:perceptualLightness(r, g, b) 返回一个颜色的 APCA 感知亮度,imageModeFromPixels(pixels, threshold) 把一段 RGBA 像素平均成 'dark' 或 'light'。