Discuss / Python / 感谢 BytesIO

感谢 BytesIO

Topic source

起风

#1 Created at ... [Delete] [Delete and Lock User]

感谢 BytesIO 让我不用先把 PIL Image 对象保存成图片, 再去读取图片请求第三方OCR识别.

用 BytesIO 做中间临时存储 bytes 非常完美.

bio = BytesIO()
pil_image.save(bio, format='png')
ret = image_ocr(bio)

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

你应该思考为什么很多库定义的接口都是

save(fp)

而不是

save(file_path)

没有那个fp接口,你就用不了BytesIO


  • 1

Reply