1

Im trying to make a sepia effect and I need to make some colors be reduced to a certain percent. My compiler errors are these:

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

This is my code:

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();
  }
2
  • Im thinking it might have to do with my new color declaration not being all integers. Commented Nov 22, 2013 at 9:10
  • Casting the values to float or int might help. Commented Nov 22, 2013 at 9:13

3 Answers 3

1

Pixel.getRed() returns an integer, so the Color(float, float, float) is useless to you. What you want is the Color(int, int, int) constructor.

0.9 is interpreted as a double, so you have to cast it to an int again after calculating your value.

Color newColor = new Color((int)(amountRed*0.9), (int)(amountGreen*0.9), (int)(amountBlue*0.9));
Sign up to request clarification or add additional context in comments.

1 Comment

+1. This is actually the correct answer, since using the constructor taking floats as argument would lead to colors that are much bigger than 1.0, which is the upper limit of the float arguments.
1

Color() cunstructor should be like this

 new Color(amountRed*0.9F, amountGreen*0.9F, amountBlue*0.9F)

or

new Color((int)(amountRed*0.9), (int)(amountGreen*0.9), (int)(amountBlue*0.9))
new Color(amountRed, amountGreen, (int)amountBlue*0.8)

0.9 is treated as double . Color dont have any cunstructor which is having double perameters. So 0.9 should be converted to float like 0.9F

2 Comments

The OP gets the color value as an integer between 0 and 255 from Pixel.getRed(). The Color(float, float, float) constructor expexts a value between 0.0 and 1.0. This just doesn't work.
@GeraldSchneider ok... Changing the answer
0

try this..

Color newColor = new Color(amountRed*0.9F, amountGreen*0.9F, amountBlue*0.9F);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.