Sou*_*uck 3 python hex image python-imaging-library
我是编程新手,所以我有一些关于将字符串转换为彩色图像的问题。
我有一个数据,它由十六进制字符串组成,就像 fff2f3 ..... 我想把这个文件转换成这样的 png。
我可以通过这个网站将十六进制数据转换为 png 图像,
但我不知道如何使用 python 代码将十六进制数据转换为 png 图像,但我尝试使用Image.frombytes('RGB',(1600,1059),hex_str)但我不知道图像大小,所以我不能使用这种方法.
所以我的问题是如何使用 python 代码将此十六进制数据转换为图像
请给我一些建议,谢谢:)
将十六进制字符串读入 bytes 对象,然后将该二进制.png文件写入文件可以这样完成:
with open('binary_file') as file:
data = file.read()
data = bytes.fromhex(data[2:])
with open('image.png', 'wb') as file:
file.write(data)
Run Code Online (Sandbox Code Playgroud)
并产生此结果,请记住它已损坏: