python - ImageDraw.draw.line(): SystemError: new style getargs format but argument is not a tuple

标签 python

我看到了多个关于此的问题,但无法找到我的问题的答案。基本上我只想在图像上画一条线,从 python 中的外部文件获取坐标。这是我的代码:

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

如果我对这些值进行硬编码,我看不出有什么问题。问题仅发生在上述情况下。谁能指出问题所在?

最佳答案

此消息通常意味着有人试图在需要元组的地方传递单独的值。

尽管pillow doc :

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

你应该坚持这个版本:

draw.line([(x, y), (endx, endy)], fill = 1)

关于python - ImageDraw.draw.line(): SystemError: new style getargs format but argument is not a tuple,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39497458/

相关文章:

没有 __init__ 的 Python 包

python - 将 PyArrayObject 数据类型转换为 C 数组

python - Beautifulsoup 和 Panda - 帮助修改多页代码

python - 通过抓取收集信息

python - 生成仅具有一项共同点的列表

python - 对 Python `processes` 的 `multiprocessing.Pool` 参数的澄清

python - OPenAI Gym Retro 错误 : "AttributeError: module ' gym. utils.seeding' 没有属性 'hash_seed'“

python - github3 0.9.6 类型错误 :pop() takes at most 1 argument (2 given)

python - 使用哪种编码在 Python 中读取意大利语文本?

python - 使用 Pug (Jade) 和 Jinja2 诱人的语法