You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
import qrcode
|
|
import os
|
|
|
|
def read_file_content(file_path):
|
|
"""读取文件内容并返回字符串"""
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
return file.read()
|
|
|
|
def generate_qr_code(data, output_path):
|
|
"""生成包含指定数据的二维码图像并保存到指定路径"""
|
|
qr = qrcode.QRCode(
|
|
version=1,
|
|
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
|
box_size=10,
|
|
border=4,
|
|
)
|
|
qr.add_data(data)
|
|
qr.make(fit=True)
|
|
|
|
img = qr.make_image(fill_color="black", back_color="white")
|
|
img.save(output_path)
|
|
|
|
# 指定文件路径
|
|
file_path = r"E:\_Ufo\000jiegou\TheBattleCar\coordinate.txt"
|
|
output_qr_path = r"E:\_Ufo\000jiegou\TheBattleCar\coordinate_qr.png"
|
|
|
|
# 检查文件是否存在
|
|
if not os.path.exists(file_path):
|
|
print(f"文件 {file_path} 不存在。")
|
|
exit(1)
|
|
|
|
# 读取文件内容
|
|
file_content = read_file_content(file_path)
|
|
|
|
# 生成二维码图像
|
|
generate_qr_code(file_content, output_qr_path)
|
|
|
|
print(f"二维码已成功生成并保存到 {output_qr_path}") |