Python PIL - 绘制圆形

Rus*_*hal 13 python imaging python-imaging-library

我试图绘制一个简单的圆圈并使用Python Imaging Library将其保存到文件中:

import Image, ImageDraw

image = Image.new('RGBA', (200, 200))
draw = ImageDraw.Draw(image)
draw.ellipse((20, 180, 180, 20), fill = 'blue', outline ='blue')
draw.point((100, 100), 'red')
image.save('test.png')
Run Code Online (Sandbox Code Playgroud)

该点draw.point出现在图像上,但椭圆本身不会出现.我尝试将模式更改为just RGB(我认为模式可能会影响显示的内容),但这并没有解决它.

我怎样才能解决这个问题?谢谢!

Mar*_*som 15

而不是指定右上角和左下角坐标,交换它们以获得左上角和右下角.

draw.ellipse((20, 20, 180, 180), fill = 'blue', outline ='blue')
Run Code Online (Sandbox Code Playgroud)


alk*_*lko 5

您的省略号坐标不正确,应该是(x1, y1, x2, y2),where x1 <= x2y1 <= y2,作为这些对,(x1, y1)(x2, y2)分别表示封闭矩形的左上角和右下角.

尝试改为

draw.ellipse((20, 20, 180, 180), fill = 'blue', outline ='blue')
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述