2014-08-27 50 views
1

任何人都可以幫我解決這個問題嗎?Jython JES:改變圖像亮度不起作用

我是新來的Jython/Python的(一般的編碼),目前我使用的是納入這一計劃稱爲JES這讓我改變圖像容易等

所以我的圖書館嘗試通過使用2個輸入來改變圖像亮度,圖片和數量。

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

我試過很多其他的方法,但他們似乎沒有工作。圖片輸入已經被分配了一個圖像btw。

我在終端鍵入改變運行程序(圖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. 

你們能幫助我嗎?謝謝

回答

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)