我认为,我成功地使用了qrcode库生成了一个代码。当我运行这个命令时,它不会抛出任何错误。现在如何将文件保存为.png
这是我到目前为止掌握的代码:
import qrcode
qr = qrcode.QRCode(version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data("This is a test string")
qr.make(fit=True)
img = qr.make_image()发布于 2015-10-14 12:24:55
您需要显式地将图像数据保存到文件中,如下所示:
with open('myfile.png', 'wb') as f:
img.save(f)编辑:显然,qrcode需要安装这些包来保存图像:
pip安装git+git://github.com/ojii/pymaging.git#egg=pymaging pip安装git+git://github.com/ojii/pymaging-png.git#egg=pymaging-png
https://stackoverflow.com/questions/33124984
复制相似问题