gpt4 book ai didi

javascript - 如何从 Vibrant js 获取 LightMulated 颜色?

转载 作者:行者123 更新时间:2023-12-03 01:29:47 24 4
gpt4 key购买 nike

我正在使用https://jariz.github.io/vibrant.js/为了从图像中获取颜色,他们在他们的网站上展示了示例,其中还显示了最白的颜色(LightMulated),但是我可以获得任何其他值,但 LightMated 不会为我返回任何内容,我怎样才能获得该颜色?我尝试像这样使用它:

            albumart.addEventListener('load', function () {
var vibrant = new Vibrant(albumart);
var swatches = vibrant.swatches()
for (var swatch in swatches)
if (swatches.hasOwnProperty(swatch) && swatches[swatch]) {
var name = (swatches.LightMuted.getHex()); // Nothing
var details = (swatches.DarkVibrant.getHex()); // Returns color

最佳答案

来自Vibrant.js

Note that some Swatches might be set to 'undefined' when Vibrant fails to find a matching color for the profile!

您可以先检查该值

var name = swatches.LightMuted ? swatches.LightMuted.getHex() 
: '#333' // default value

关于javascript - 如何从 Vibrant js 获取 LightMulated 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51355892/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com