【问题标题】:Jython JES: Changing brightness of image won't workJython JES:更改图像亮度不起作用
【发布时间】:2014-08-27 10:47:55
【问题描述】:

谁能帮帮我?

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

你们能帮帮我吗?谢谢

【问题讨论】:

    标签: python jython brightness jes


    【解决方案1】:

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

    color r=255 g=255 b=255
    

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

    现在你的问题是makeColor() 方法只接受color 的对象作为它的参数。目前您正尝试将 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-28
      • 2012-10-10
      • 1970-01-01
      相关资源
      最近更新 更多