例子 画出一个灰色的线
from PIL import Image, ImageDraw
im = Image.open("hopper.jpg")
draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0, im.size[1], im.size[0], 0), fill=128)
del draw
# write to stdout
im.save(sys.stdout, "PNG")
基本概念
坐标系
和PIL使用同样的坐标系.(0,0)位于左上角
颜色
类型 | 参数 |
---|---|
“1”,”L”,”I” | 使用integers |
“RGB” | 3个长度的元组,每个位上是 integers |
“F” | integers或者floating |
“P” | color indexes或者RGB 3-tuples或者clolor name |
创建绘图对象
class PIL.ImageDraw.Draw(im, mode=None)
方法 | 描述 |
---|---|
getfont() | 获得默认的font |
arc(xy, start, end, fill=None) | 做圆 |
bitmap(xy, bitmap, fill=None) | 画bitmap(mask) |
chord(xy, start, end, fill=None, outline=None) | 类似arc(),起点和终点会连起来 |
ellipse(xy, fill=None, outline=None) | 椭圆 |
line(xy, fill=None, width=0) | 直线 |
pieslice(xy, start, end, fill=None, outline=None) | 类似arc() |
point(xy, fill=None) | 画点 |
polygon(xy, fill=None, outline=None) | 多边形 |
rectangle(xy, fill=None, outline=None) | 长方形 |
text(xy, text, fill=None, font=None, anchor=None, spacing=0, align=”left”, direction=None, features=None) | 文字 |
multiline_text(xy, text, fill=None, font=None, anchor=None, spacing=0, align=”left”, direction=None, features=None) | |
textsize(text, font=None, spacing=4, direction=None, features=None) | 返回当前字符串的大小 |
multiline_textsize(text, font=None, spacing=4, direction=None, features=None) | |
floodfill(image, xy, value, border=None, thresh=0) | 填充选中区域 |
参考文献:
http://pillow.readthedocs.io/en/latest/reference/ImageDraw.html