【问题标题】:Python3 Steganography / stepic / ValueError: Unsupported pixel format: image must be RGB, RGBA, or CMYKPython3 隐写术/stepic/ValueError:不支持的像素格式:图像必须是 RGB、RGBA 或 CMYK
【发布时间】: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


【解决方案1】:

在将图像传递给stepic.encode() 之前,请尝试将其转换为任何受支持的格式。示例代码如下:

from PIL import Image
import stepic

i = input("Name of File (With extension): ")
img = Image.open(i)

message = input("Message: ")

message = message.encode()

imgConv = img.convert("RGB") # Here
encoded_img = stepic.encode(imgConv, message)

encoded_img.save(input("Name of encypted image: "))
print("Completed!")

【讨论】:

    猜你喜欢
    • 2018-07-23
    • 2020-05-15
    • 2013-05-26
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    相关资源
    最近更新 更多