跳轉到內容

Python 影像庫/檔案 I/O

來自華夏公益教科書

PIL 中的檔案操作非常簡單,並且反映了正常的 Python 方法。

import Image

img = Image.open(filepath)
from PIL import Image

img = Image.open("path/to/image.ext")
pixels = img.load() # Load the pixels of the image into a matrix

在視窗中顯示指定影像的副本。

from PIL import Image

img = Image.open("path/to/image.ext")

img.show() # Shows the image in a new window
import Image

img = Image.open(filepath)
img.save("example.png")

#img.save(outfile, options...)
#img.save(outfile, format, options...)
華夏公益教科書