2016-09-14 8 views
0

これに複数の質問がありましたが、私の問題に対する答えを見つけることができませんでした。基本的には、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) 

:ハードコードi値は、私が表示された場合

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 

を問題はありません。問題は上記の場合にのみ発生します。誰も問題を指摘できますか?

+0

あなたが示している、とあなたが見るエラーが同じではありませんコード:あなたはこのバージョンに固執する必要があり

xy – Sequence of either 2-tuples like [(x, y), (x, y), ...] or numeric values like [x, y, x, y, ...].

pillow docにもかかわらず

。この行はどこにありますか? 'draw.line(([x、y]、[endx、endy])、fill = 1)'? – karthikr

+0

エラーを更新しました。基本的に、エラーは最後の行の前にあります。何が問題なのか教えてください。 – user3193684

答えて

0

int(...)のように見えますか?

--- a.py.ORIG 2016-09-14 20:54:47.442291244 +0200 
+++ a.py 2016-09-14 20:53:34.990627259 +0200 
@@ -1,4 +1,4 @@ 
-import Image, ImageDraw 
+from PIL import Image, ImageDraw 
import sys 
import csv 
im = Image.open("screen.png") 
@@ -8,13 +8,13 @@ 
    for row in reader: 
     if row[0] == 'H': 
     print "Horizontal line" 
-  endx = row[2] 
+  endx = int(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] 
+  endx = int(row[2])+int(row[1]) 
+  endy = int(row[3]) 
+  x = int(row[2]) 
+  y = int(row[3]) 
     draw.line((x,y, endx,endy), fill = 1) 
    im.show() 
1

このメッセージは、タプルが予想される場所で別々の値を渡そうとすることがよくあります。

draw.line([(x, y), (endx, endy)], fill = 1) 
関連する問題