我正在尝试将图像的饱和度更改一定量,但得到一些奇怪的结果。我正在使用以下代码
// 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
如您所见,在最后一张图像中,颜色非常失真。有人知道如何解决这个问题吗?