python - Jython JES : Changing brightness of image won't work

标签 python jython brightness jes

有人可以帮我吗?

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

你们能帮帮我吗?谢谢

最佳答案

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

color r=255 g=255 b=255

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

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

  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)

关于python - Jython JES : Changing brightness of image won't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25525179/

相关文章:

iphone - 更改屏幕亮度,就像 iBook 一样

swift - 当 UIScreen 亮度改变时添加动画淡入淡出效果(Swift)

python - 在 Python 图像库中将 EPS 文件转换为 PNG 时更改输出分辨率

Python:为什么每个键添加字典值取决于顺序?

python - Matplotlib 中的重音字符

python - 使用子进程模块从 python 启动 jython 程序?

java - Python 解释器 Jython - 模块的执行

使用 Jython 脚本的 Java 代码

macos - 在 Mac OS X 应用程序中调整屏幕亮度

python - 如何使用 xbbg python 库从 Bloomberg 下载报价数据?