簡體   English   中英

從Python io.BufferedReader類的實例讀取/打開圖像

[英]Read/Open image from instance of Python io.BufferedReader class

我正在努力從Python的io.BufferedReader類的實例中正確打開TIFF圖像。 我使用下面的lib從GCS路徑下載圖像,但是我無法打開似乎用傳統工具打開圖像。

# returns the <_io.BufferedReader>
file = beam.io.gcp.gcsio.GcsIO().open("<GCS_PATH>", 'r')

from PIL import Image    
img = Image.open(file.read()) <---- Fails with "TypeError: embedded NUL character"

img = Image.open(file.raw) <--- Fails when any operations are performed with "IOError(err)"

我對PIL以外的其他圖書館開放。

UPDATE

以下也失敗了:

img = Image.open(file)

它失敗並出現IOError,說明tempfile.tif: Cannot read TIFF header.

確保將它們都包裝在ContextManager中,以便它們都能正確關閉。

with beam.io.gcp.gcsio.GcsIO().open(file_path, 'r') as file, Image.open(io.BytesIO(file.read())) as multi_page_tiff:
     do_stuff()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM