首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python3隐写/步骤/ ValueError:不支持的像素格式:图像必须是RGB、RGBA或CMYK

Python3隐写/步骤/ ValueError:不支持的像素格式:图像必须是RGB、RGBA或CMYK
EN

Stack Overflow用户
提问于 2021-08-31 03:37:14
回答 1查看 36关注 0票数 0

我是python的新手,我正在尝试隐写术。我正在使用Stepic和image库来尝试将用户输入消息加密到任何图像上。我的脚本会做得很好,直到最后一步,对图像进行加密。我的错误是,"ValueError:不支持的像素格式:图像必须是RGB、RGBA或CMYK“我想不出任何可以尝试的方法,所以我来到这里。下面是我的代码:

代码语言:javascript
复制
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!")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-31 04:38:28

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

代码语言:javascript
复制
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!")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68992557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档