1

can anyone help me out here?

I'm new to Jython/Python (coding in general) and I'm currently using the library that is included into this program called JES which allows me to alter images easily etc.

So I'm try to alter this images brightness by using 2 inputs, the picture and the amount.

def change(picture, amount):
  for px in getPixels(picture):
   color = getColor(px)
   alter = makeColor(color * amount)
   setColor(px, alter)

An I've tried many other methods but they don't seem to work. The picture input has already been assigned an image btw.

I run the program in terminal by typing change(picture, 0.5) which should make the image 50% brighter but I keep getting this error:

>>> change(picture, 0.5)
The error was: 'instance' and 'float'
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type. This means               that you did something such as trying to pass a string to a method that is expecting an integer.

Can you guys help me out? Thanks

james
  • 55
  • 1
  • 1
  • 6

1 Answers1

1

Try printing the variable color to the console. You will notice the following on the console:

color r=255 g=255 b=255

This is because the method getColor(px) returns an object of color. This object has 3 properties r,g,b which represent the color the red, green, blue values of the pixel px.

Now your problem is that the method makeColor() only accepts an object of color as its argument. At the moment you are trying to multiply a color by amount, but you need to deal with numbers rather than colors when you multiply.

  def change(picture, amount):

    for px in getPixels(picture):
      # Get r,g,b values of the pixel and 
      myRed = getRed(px) / amount
      myBlue = getBlue(px) / amount
      myGreen = getGreen(px) / amount

      # use those values to make a new color
      newColor = makeColor(myRed, myGreen, myBlue)
      setColor(px, newColor)
PrairieProf
  • 174
  • 11
super_mario3d
  • 95
  • 1
  • 5