Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的用例:我想使用 PIL 中的 ImageOps.expand 方法为图像添加 10 像素的边框。它要求填充值,默认为黑色。我研究发现,为了找到一个像素的颜色值,你需要做
pix = im.load() im = ImageOps.expand(im, border=10, fill=pix[0,0])
问题:我无法将此pix[x,y]值传递给 expand 方法。我浏览了方法定义,但找不到失败的确切原因。这是要求您发送填充值的 PIL 的官方文档。
pix[x,y]
我能够得到这种图像。唯一错误的是烦人的白色边框,即使我使用填充值作为 pix[0,0]。
以下对我有用:
from PIL import Image, ImageOps img = Image.open('skooter.png') x, y = 0, 0 pix = img.load() img2 = ImageOps.expand(img, border=10, fill=pix[x,y]) img2.show()
结果: