我看到了多個問題,但無法找到我的問題的答案。基本上我只想在圖像上畫一條線,從python的外部文件中獲取座標。而在這裏不用我的代碼:ImageDraw.draw.line():SystemError:新樣式getargs格式,但參數不是元組
import Image, ImageDraw
import sys
import csv
im = Image.open("screen.png")
draw = ImageDraw.Draw(im)
with open("outputfile.txt") as file:
reader = csv.reader(file, delimiter=' ')
for row in reader:
if row[0] == 'H':
print "Horizontal line"
endx = row[2]
endy = int(row[3])+int(row[1])
elif row[0] == 'V':
print "Vertical line"
endx = row[2]+row[1]
endy = row[3]
x = row[2]
y = row[3]
draw.line((x,y, endx,endy), fill = 1)
im.show()
一切正常,除了行:
draw.line((x,y, endx,endy), fill = 1)
在那裏我看到以下錯誤:
File "dummy_test.py", line 21, in <module>
draw.line((x,y, endx,endy), fill = 1)
File "/Library/Python/2.7/site-packages/PIL-1.1.7-py2.7-macosx-10.10- intel.egg/ImageDraw.py", line 200, in line
self.draw.draw_lines(xy, ink, width)
SystemError: new style getargs format but argument is not a tuple
如果我硬編碼的價值觀,我看沒問題。問題只發生在上述情況。任何人都可以指出問題嗎?
你所示的代碼,你看到的錯誤是不一樣的。這條線在哪裏:'draw.line(([x,y],[endx,endy]),fill = 1)'? – karthikr
更新了錯誤。基本上錯誤是在最後一行之前。你可以討論什麼是問題? – user3193684