How to get image from ImageDraw in PIL?

后端 未结 1 1299
轮回少年
轮回少年 2021-02-09 09:32

I am using PIL for my project and I have ImageDraw object. I want to get the image that is drawn on ImageDraw object. How do I get the image ?

1条回答
  •  名媛妹妹
    2021-02-09 10:12

    Is THIS what you are looking for?

    from PIL import Image, ImageDraw
    im = Image.new('RGBA', (400, 400), (0, 255, 0, 0))
    draw = ImageDraw.Draw(im) 
    draw.text((20, 20), "DRAW TEXT", fill="red")
    draw.polygon([(5,5), (25,5), (25,20), (5,25)], fill="green", outline=None)
    im.show()
    im.save("ImageDraw.png")
    

    Here is the ImageDraw.png image file (resized 300%):

    Here the draw object is used for drawing polygons in the image. While drawing to the draw object you changed the im object.

    P.S. check out also :

    Drawing a line on an image with pil

    Python imaging library save function

    0 讨论(0)
提交回复
热议问题