我有一个QPainterPath,我想裁剪一个图像,它是QPixmap。 这段代码对我有用,但我想使用PyQt5内置功能 就像面具没有纽姆
# read image as RGB and add alpha (transparency)
im = Image.open("frontal_1.jpg").convert("RGBA")
# convert to numpy (for convenience)
imArray = numpy.asarray(im)
# create mask
polygon = [(444, 203), (623, 243), (691, 177), (581, 26), (482, 42)]
maskIm = Image.new('L', (imArray.shape[1], imArray.shape[0]), 0)
ImageDraw.Draw(maskIm).polygon(polygon, outline=1, fill=1)
mask = numpy.array(maskIm)
...
newIm = Image.fromarray(newImArray, "RGBA")
newIm.save("out.png")
替换mask的一种可能方法是使用qpaint的setClipPath()方法:
在回答了上面的问题后,我稍微修改了一下代码,现在它看起来像:
相关问题 更多 >
编程相关推荐