# 读取文件的字节流数据,将其转换为十六进制(读取image_file路径下的图像)
image_file="C:/Users/DELL/Desktop/src/2.jpg"
if len(image_file)!=0:
with open(image_file1, 'rb') as file_byte:
file_hex = file_byte.read().hex()
# 十六进制转化为字节流文件写入(输出到image_file路径)
lines = file_hex
res = [lines[i:i + 2] for i in range(0, len(lines), 2)]
with open(image_file, "wb") as f:
for i in res:
s = struct.pack('B', int(i, 16))
f.write(s)
``
python 将图像文件字节流转换成十六进制字符串读入读出
于 2022-11-03 11:25:55 首次发布