2012-10-09 41 views
4

我想寫一個python函數來將圖片的右半部分鏡像到左半邊。到目前爲止,我有這個代碼,但它的工作方式相反(它反映從L到R)我知道它必須是一些簡單的更改,但現在我似乎有一個塊。任何幫助讚賞。從R到L垂直鏡像圖像的Python函數

def mirrorVertical(source): 
    mirrorPoint = getWidth(source)/2 
    width = getWidth(source) 
    for y in range(0,getHeight(source)): 
    for x in range(0,mirrorPoint): 
     leftPixel = getPixel(source,x,y) 
     rightPixel = getPixel(source,width - x - 1,y) 
     color = getColor(leftPixel) 
     setColor(rightPixel,color) 

回答

0
color = getColor(rightPixel) 
    setColor(leftPixel,color) 
+0

謝謝,我知道這很簡單 – user1729377

0

看起來好像你是從左上角到中間,而不是右側角落到中間。可能想爲x嘗試範圍(getWidth(),mirrorPoint)並讓y相同。

0

改變rightPixel的顏色之前,您應該保存此顏色的地方,以便將其設置在leftPixel

喜歡的東西

color_left = getColor(leftPixel) 
color_right = getColor(rightPixel) 
setColor(leftPixel, color_right) 
setColor(rightPixel, color_left) 

應該做的伎倆。