How do you draw transparent polygons with Python?

后端 未结 7 1316
独厮守ぢ
独厮守ぢ 2020-12-05 10:28

I\'m using PIL (Python Imaging Library). I\'d like to draw transparent polygons. It seems that specifying a fill color that includes alpha level does not work. Are their

7条回答
  •  甜味超标
    2020-12-05 11:00

    PIL's Image module provides a blend method.

    Create a second image the same size as your first, with a black background. Draw your polygon on it (with full colour). Then call Image.blend passing the two images and an alpha level. It returns a third image, which should have a semi-transparent polygon on it.

    I haven't measured the performance (hey, I haven't even tried it!) so I cannot comment on it's suitability. I suggest you work out your performance budget, and then measure it to see if it is fast enough for your purposes.

提交回复
热议问题