有人可以帮我吗?
我是 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/