Pillow学习之ImageDraw

来源:互联网 发布:青山软件破解版 编辑:程序博客网 时间:2024/06/06 20:09
导入ImageDraw
from PIL import ImageDraw,Image
创建一400*400白色图片
im = Image.new('RGB',(400,400),'white')
创建对象
#函数原型#class PIL.ImageDraw.Draw(im, mode=None)draw = ImageDraw.Draw(im)
arc方法
#函数原型#PIL.ImageDraw.Draw.arc(xy, start, end, fill=None)draw.arc((150,150,250,250),0,180,'red')#以(200,200)为圆心,50为半径,作一开口向上的红色半圆弧
chord方法
#函数原型#PIL.ImageDraw.Draw.chord(xy,start,end,fill=None,outline=None)draw.chord((150,150,250,250),180,360,'blue','green')#以(200,200)为圆心,50为半径,作一外边缘绿色,填充蓝色弓形
ellipse方法
#函数原型#PIL.ImageDraw.Draw.ellipse(xy, fill=None, outline=None)draw.ellipse((150,150,250,350),'yellow','green')#在给定范围内作一外边缘绿色,填充黄色的椭圆


line方法
#函数原型#PIL.ImageDraw.Draw.line(xy, fill=None, width=0)draw.line(((50,60),(270,356)),'red',5)#在给定两点间作一宽5像素的红色直线
pieslice方法
#函数原型#PIL.ImageDraw.Draw.pieslice(xy,start,end,fill=None,outline=None)draw.pieslice((150,150,250,350),0,90,'gold','purple')在给定范围内作一外边缘紫色,填充金色的扇形
point方法
#函数原型#PIL.ImageDraw.Draw.point(xy, fill=None)draw.point((150,150),'black')#将指定点改成黑色
polygon方法
#函数原型#PIL.ImageDraw.Draw.polygon(xy, fill=None, outline=None)draw.polygon(((10,10),(10,20),(20,10)),'gold','brown')#棕色连接给定点,金色填充的多边形
rectangle方法
#函数原型#PIL.ImageDraw.Draw.rectangle(xy, fill=None, outline=None)draw.rectangle((150,150,250,350),'teal')#给定范围作一蓝绿色长方形
text方法
#函数原型#PIL.ImageDraw.Draw.text(xy, text, fill=None, font=None, anchor=None, spacing=0, align=”left”)draw.text((100,100),'Hello Triagen!','green')#以指定位置为左上角用绿色写出指定字符
textsize方法
#函数原型#PIL.ImageDraw.Draw.textsize(text, font=None, spacing=0)#返回给定text的像素大小
setfont方法
#函数原型#PIL.ImageDraw.Draw.setfont(font)#指定默认字体

0 0
原创粉丝点击