Tristan
Tristan

Reputation: 1790

Why is aggdraw image blank?

I am trying to draw a bunch of line segments using Pillow and aggdraw. With just pillow, my code was working - but I needed much smoother lines. I can't seem to get any lines drawn with aggdraw.

import aggdraw
from PIL import Image

image = Image.new("RGB", (ROW_SIZE, COL_SIZE), (255,255,255))
#draw = ImageDraw.Draw(image)
draw = aggdraw.Draw(image)
pen = aggdraw.Pen("black", 2)

# Each segment contains two points with x and y coordinates
for segment in segments:
   draw.line((segment.point1.x, segment.point1.y, segment.point2.x, segment.point2.y), pen)

image.show()

I also tried changing the import to from aggdraw import Draw, Pen and changing the usage accordingly - to no avail.

Upvotes: 1

Views: 138

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207758

Try using:

...
for segment in segments:
    draw.line((segment.point1.x, segment.point1.y, segment.point2.x, segment.point2.y), pen)

# Add the following line
draw.flush()
image.show()

Upvotes: 0

Related Questions