如何转型图片对象到缓冲区字符串?

2024-09-10 15:10:01 发布

您现在位置:Python中文网/ 问答频道 /正文

sbuf = StringIO()
sbuf.write(decoded_file)
pimg = Image.open(sbuf)

print pimg.size

cimage = StringIO()
pimg.seek(0)
pimg.save(cimage,'jpeg')
contents = cimage.getvalue()
if contents == decoded_file:
   print '1------->> ok!'

“decoded_file”是图像缓冲区字符串。我要转换图片对象“pimg”到“contents”和“contents”应等于“decoded_file”。在


Tags: imagesizesavecontentsseekopenfilewrite