__init__.py
import io import os from PIL.Image import Image content = '二進制數據' byte_stream = io.BytesIO(content) # 請求數據轉化字節流 roiImg = Image.open(byte_stream) # Image打開二進制流Byte字節流數據 imgByteArr = io.BytesIO() # 創建一個空的Bytes對象 roiImg.save(imgByteArr, format='PNG') # PNG就是圖片格式 imgByteArr = imgByteArr.getvalue() # 保存的二進制流 path = '存儲文件目錄' name = 'test.png' # 生成文件目錄 if not os.path.exists(path): os.makedirs(path) # 創建圖片 with open(path+name, "wb+") as f: f.write(imgByteArr)
