Python PIL - 画圆

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20747345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 21:09:01  来源:igfitidea点击:

Python PIL - Draw Circle

pythonpython-imaging-libraryimaging

提问by Rushy Panchal

I am trying to draw a simple circle and save this to a file using the Python Imaging Library:

我正在尝试绘制一个简单的圆圈并将其保存到使用 Python 图像库的文件中:

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')

The point draw.pointappears on the image, but the ellipse itself does not. I tried changing the mode to just RGB(I thought the mode might affect what is displayed), but this did not solve it.

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

How can I fix this? Thanks!

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

采纳答案by Mark Ransom

Instead of specifying the upper right and lower left coordinates, swap them to get the upper left and lower right.

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

draw.ellipse((20, 20, 180, 180), fill = 'blue', outline ='blue')

回答by alko

Your ellipsis coordinates are incorrect, that should be (x1, y1, x2, y2), where x1 <= x2and y1 <= y2, as those pairs, (x1, y1)and (x2, y2), represents respectively top left and bottom right corners of enclosing rectangle.

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

Try to change to

尝试更改为

draw.ellipse((20, 20, 180, 180), fill = 'blue', outline ='blue')

enter image description here

在此处输入图片说明