【发布时间】:2021-10-29 16:54:09
【问题描述】:
我对 python 还很陌生,我正在尝试隐写术。我正在使用库 Stepic 和 Image 尝试将用户输入消息加密到任何图像上。我的脚本会一直运行良好,直到最后一步,即对图像进行加密。我的错误是,“ValueError:不支持的像素格式:图像必须是 RGB、RGBA 或 CMYK”我想不出任何可以尝试的方法,所以我来到了这里。 这是我的代码:
from PIL import Image
import stepic
i = input("Name of File (With extension): ")
img = Image.open(i)
message = input("Message: ")
message = message.encode()
encoded_img = stepic.encode(img, message)
encoded_img.save(input("Name of encypted image: "))
print("Completed!")
【问题讨论】:
-
那么,您的图像是什么格式?您可能只需要在某个时候对其应用
.convert('RGB')。 -
@jasonharper 这是一个 png。我有点困惑,我该在哪里添加 convert('RGB') 非常感谢,- Ali
标签: python python-3.x steganography stepic