我試圖使一個棕褐色效果,我需要使一些顏色減少到一定的百分比。我的編譯器錯誤是這些:爪哇顏色undefined
Error: The constructor java.awt.Color(double, double, double) is undefined
Error: The constructor java.awt.Color(int, int, double) is undefined
Error: The constructor java.awt.Color(int, int, double) is undefined
這是我的代碼:
public void sepiaTint()
{
Pixel[] pixelArray = this.getPixels();
for (int i = 0; i < pixelArray.length; i++)
{
Pixel pixelObj = pixelArray[i];
int amountRed = pixelObj.getRed();
int amountGreen = pixelObj.getGreen();
int amountBlue = pixelObj.getBlue();
if (amountRed < 60)
{
Color newColor = new Color(amountRed*0.9, amountGreen*0.9, amountBlue*0.9);
pixelObj.setColor(newColor);
}
if (amountRed >= 60 && amountRed <190)
{
Color newColor = new Color(amountRed, amountGreen, amountBlue*0.8);
pixelObj.setColor(newColor);
}
else
{
Color newColor = new Color(amountRed, amountGreen, amountBlue*0.9);
pixelObj.setColor(newColor);
}
}
this.repaint();
}
林認爲這可能與我的新顏色聲明不是所有整數。 – user2984690
將這些值轉換爲'float'或'int'可能會有所幫助。 –