我正在为处理学校的作业制作一个音乐播放器.飞利浦Hue灯将产生一些相应的视觉效果.我想让每首歌的视觉效果都是独一无二的.因此,我获取了播放曲目的封面艺术(使用LastFM API)以获得最常用的颜色,并将其用作创建其他颜色的基础.飞利浦Hue有一种不同的显示颜色的方式即(HSB).所以我通过转换它
Color.RGBtoHSB();
对于前者 它给出了R = 127,G = 190,B = 208,其值H = 0.5370371,S = 0.38942307,B = 0.8156863.现在我猜它们是在基数1上计算的,所以我将亮度和饱和度乘以255.而Hue乘以65535.(见http://developers.meethue.com/1_lightsapi.html)
在飞利浦Hue中设置这些计算值时,无论播放什么歌曲,颜色总是红色或白色.
RGB到HSB之间的转换出了什么问题?
在流行的请求我的代码:
作为测试:
Color c = Colorconverter.getMostCommonColour("urltoimage");
float[] f = Colorconverter.getRGBtoHSB(c);
ArrayList<Lamp> myLamps = PhilipsHue.getInstance().getMyLamps();
State state = new State();
state.setBri((int) Math.ceil(f[2]*255));
state.setSat((int) Math.ceil(f[1]*255));
state.setHue((int) Math.ceil(f[0]*65535));
state.setOn(true);
PhilipsHue.setState(myLamps.get(1), state);
Run Code Online (Sandbox Code Playgroud)
功能如上所示
public static Color getMostCommonColour(String coverArtURL) {
Color coulourHex = null;
try {
BufferedImage image = ImageIO.read(new URL(coverArtURL));
int height = image.getHeight();
int width = image.getWidth();
Map m = new HashMap(); …Run Code Online (Sandbox Code Playgroud)