如何解决Java更改饱和度导致颜色失真
我正在尝试将图像的饱和度更改一定量,但得到一些奇怪的结果。我正在使用以下代码
// shiftAmount should be a float value between -1 and 1
public static int[] saturation( int[] pixels,float shiftAmount )
{
int[] newPixels = new int[ pixels.length ];
for( int i = 0; i < pixels.length; i++ )
{
// get HSB color values
Color rgb = new Color( pixels[ i ] );
float[] hsb = Color.RGBtoHSB( rgb.getRed(),rgb.getGreen(),rgb.getBlue(),null );
float hue = hsb[ 0 ];
float saturation = hsb[ 1 ];
float brightness = hsb[ 2 ];
// shift
saturation += shiftAmount;
if( saturation > 1f )
saturation = 1f;
else if( saturation < 0f )
saturation = 0f;
// convert HSB color back
newPixels[ i ] = Color.HSBtoRGB( hue,saturation,brightness );
}
return newPixels;
}
以下是另一个图像编辑软件(Aseprite)中的80%饱和度偏移的示例,而我使用自己的代码(使用0.8f)完成了此操作。
What it looks like when I use Aseprite
What it looks like using my own code
如您所见,在最后一张图像中,颜色非常失真。有人知道如何解决这个问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。