IllegalArgumentException: Color parameter outside of expected range: Red Green Blue

╄→гoц情女王★ 提交于 2019-12-02 01:36:00

You are calling the Color constructor with three float parameters so the values are allowed to be between 0.0 and 1.0.

But color.getRed() (Blue, Green) can return a value up to 255. So you can get the following:

float greyscale = ((0.299f *255) + (0.587f * 255) + (0.144f * 255));
System.out.println(greyscale); //262.65

Which is far to high for 1.0f and even for 252 which the Color(int,int,int) constructor allows. So scale your factors like dasblinkenlight said and cast the greyscale to an int or else you will call the wrong constructor of Color.`

new Color((int)greyscale,(int)greyscale,(int)greyscale);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!