1

有谁可以帮我离开这里吗?

我是 Jython/Python 的新手(一般编码),我目前正在使用这个程序中包含的名为 JES 的库,它允许我轻松更改图像等。

因此,我尝试通过使用 2 个输入(图片和数量)来更改此图像的亮度。

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

我尝试了许多其他方法,但它们似乎不起作用。顺便说一句,图片输入已经分配了一个图像。

我通过键入 change(picture, 0.5) 在终端中运行程序,这应该会使图像变亮 50%,但我不断收到此错误:

>>> 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.

你们能帮帮我吗?谢谢

4

1 回答 1

1

尝试将变量打印color到控制台。您会在控制台上注意到以下内容:

color r=255 g=255 b=255

这是因为该方法getColor(px)返回一个颜色对象。这个对象有 3 个属性 r,g,b 代表像素的红色、绿色、蓝色值的颜色px

现在你的问题是该方法makeColor()只接受一个对象color作为它的参数。目前您正试图将颜色乘以amount,但是当您相乘时需要处理数字而不是颜色。

  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)
于 2014-08-28T11:22:29.473 回答