Python ValueError:从bash管道读取png文件时嵌入的空字节

前端之家收集整理的这篇文章主要介绍了Python ValueError:从bash管道读取png文件时嵌入的空字节前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

from PIL import Image
from subprocess import Popen,PIPE

scr = Image.open(Popen.communicate(Popen(['import','-w','0x02a00001','png:-'],stdout=PIPE))[0])

错误

  File "/usr/lib/python3/dist-packages/PIL/Image.py",line 2258,in open
    fp = builtins.open(filename,"rb")
ValueError: embedded null byte
最佳答案
首先尝试将原始数据加载到BytesIO容器中:

from io import BytesIO
from PIL import Image
from subprocess import Popen,PIPE

data = Popen.communicate(Popen(['import',stdout=PIPE))[0]
scr = Image.open(BytesIO(data))
原文链接:https://www.f2er.com/linux/440470.html

猜你在找的Linux相关文章