[英]loading png from json file using PIL
我正在嘗試使用 PIL.Image.open 從打開的 json 文件中打開圖像。 我應該將 png 文件的名稱放在 Image.open() 中還是它是導致 json 文件的目錄?
謝謝
這是一個完整的示例,可能是您正在尋找的:
import json
from PIL import Image
with open('yourfilename.txt', 'r') as f:
data = json.load(f)
# Load the file path from the json
imgpath = data['yourkey']
# Place the image path into the open method
img = Image.open(imgpath)
imgpath
變量應返回圖像路徑的字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.