python - Changing the value of pixel in an image
问题描述
I am working with stenography. I need to hide data in pixel of an image.But I am fetching problem when I am trying to update the value of pixel. I tried the code below:
from PIL import Image
im = Image.open('./data/frame398.png')
pix = im.load()
r, g, b = pix[200,200]
print("Pre RGB")
print(r, g, b)
pix[200,200] = 0,0,0
It should change the value of the pixel to (0,0,0). But it doesn't. If I try the code below:
imx = Image.open('./data/frame398.png')
pixx = imx.load()
r, g, b = pixx[200,200]
print("Post RGB")
print(r, g, b)
I got the output below:
Pre RGB
69 62 65
Post RGB
69 62 65
Instead of (0,0,0) I am getting the old value. What I am doing wrong? I need help.Thanks
解决方案
您已成功更改图像,但如果您想再次读取它,则需要将其写入文件:
要保存到同一个图像文件,只需执行
im.save('./data/frame398.png', ‘PNG’)
推荐阅读
- java - 创建一个对象以在多个 TestNG 类之间共享数据
- cloud-foundry - 将文件夹复制到 Pivotal Cloud Foundry
- asp.net-core - 如何在 asp.net 核心中将 Map 插入到 dynamodb 表
- c# - 调用 EntityTypeBuilder
.HasKey 通过反射获得复合键 - java - java.util.zip.ZipException: 无效代码 -- 缺少块尾 --> 在调用 ZipInputStream.closeEntry() 时
- apache-kafka - kafka 中的 b/w group.id、application.id 和 client.id 有什么区别?
- c - 如何在c中写入绝对值
- azure - 将 Dynamics CRM 部署到 Azure 虚拟机时的最佳实践
- typescript - 'DocumentData | 类型的参数 undefined' 不可分配给“DocumentData”类型的参数
- http - 用特殊字符编码文件名以上传到 jmeter 中的 post Http 请求