繪制線的代碼如下:
draw = ImageDraw.Draw(image_frame)
draw.polygon([(left, top), (left+width-1, top), (left+width-1, top+height-1), (left, top+height-1)], outline=(255, 0, 0))
儲存為圖檔時會發現,線隻有一個像素,怎麼辦?這個時候,移動一個像素,再繪制一次:
left += 1
top += 1
draw.polygon([(left, top), (left+width-1, top), (left+width-1, top+height-1), (left, top+height-1)], outline=(255, 0, 0))
如果覺得還是不夠粗,再移動像素繪制.