如何关闭Pillow中打开的图像?

Cha*_*ell 32 python python-imaging-library pillow

我有一个导入Pillow库的python文件.我可以打开图像

Image.open(test.png)
Run Code Online (Sandbox Code Playgroud)

但是如何关闭该图像呢?我没有使用Pillow来编辑图像,只是为了显示图像并允许用户选择保存或删除它.

Mor*_*app 56

Image.close().

你也可以用一个块来做:

with Image.open('test.png') as test_image:
    do_things(test_image)
Run Code Online (Sandbox Code Playgroud)

使用示例Image.close():

test = Image.open('test.png')
test.close()
Run Code Online (Sandbox Code Playgroud)

  • 我知道这是一篇非常旧的帖子,但在我的 Mac 上 .close() 没有执行任何操作。文件在预览中打开,并在调用 .close() 后保持打开状态。 (3认同)