【发布时间】:2021-06-08 01:23:13
【问题描述】:
我已使用以下程序将 png 图像转换为基本的 2 位序列
from PIL import Image, ImageFile
from io import BytesIO
out = BytesIO()
with Image.open("download.png") as img:
img.save(out, format="png")
image_in_bytes = out.getvalue()
encoded_b2 = "".join([format(n, '08b') for n in image_in_bytes])
w = open("bitofimage", "w")
w.write(encoded_b2)
因此,是一个基数为 2. 的位序列
我创建了一个 CRC 过程并在其后面的位缝中添加了 8 个位。
然后使用此代码转换回 PNG 图像
a = open("bitadd_crc","r") //This Stream of bit has add with 8 bit crc
konv = a.read()
decoded_b2 = [int(konv[i:i + 8], 2) for i in range(0, len(konv), 8)]
with open('YANGDIKIRIM.png', 'wb') as f:
f.write(bytes(decoded_b2))
f.close()
w.close()
再次转换为图像后,它可以工作,但是当我再次将其解压缩为一系列位时,之前添加的 8 位 CRC 无法读取并转换为图像的一部分。谁能帮我找到解决方案? 我希望能帮助我完成最后的学校作业
感谢您的帮助
【问题讨论】:
标签: python-3.x image-processing type-conversion png bytesio