python-3.x - TypeError:“PngImageFile”对象不可迭代
问题描述
我正在使用 PIL 在图像的二进制文件中编码一些加密数据。这是我的代码:
from PIL import Image
image_location=input("Enter the image to encode : ")
image = Image.open(image_location)
image.save("Encoded_"+image_location)
modify_img=Image.open("Encoded_"+image_location)
img_size=modify_img.height * modify_img.width
print("[*]Maximum bytes to encode : ",img_size)
payload="01110100 01100101 01110011 01110100 "
for row in modify_img:
for pixel in row:
#for red
if data_index < data_len:
pixel[0] = int(r[:-1] + binary_secret_data[data_index], 2)
data_index += 1
#for green
if data_index < data_len:
pixel[0] = int(g[:-1] + binary_secret_data[data_index], 2)
binary_secret_data += 1
#for blue
if data_index < data_len:
pixel[0] = int(b[:-1] + binary_secret_data[data_index], 2)
data_index += 1
if data_index >= data_len:
break
我得到了这个错误:
Traceback (most recent call last):
File "image.py", line 14, in <module>
for row in image:
TypeError: 'PngImageFile' object is not iterable
一些建议请`
解决方案
推荐阅读
- python - 如何在 Python 的 for 循环中检索剩余项目?
- css - Material UI ReactJS如何在没有组件“移动”效果的情况下很好地对齐
- python - 创建一个类的对象来测试一个方法python
- regex - 将同一个单词中混合大小写分成两行
- jenkins-pipeline - 在 Groovy\Jenkins 中是否有一个可以将毫秒转换为秒的班轮
- html - 让屏幕阅读器读取 javascript 创建的对话框中的内容
- python - pythonhackerrank问题中的字典RUNTIME问题(菜鸟问题)
- asp.net-core - 如何修改 .Aspnetcore.Identity.Application Cookie 名称?
- java - Intellij Idea 的远程调试失败并出现错误:调试器无法附加:握手失败 - 连接过早关闭
- visual-studio - 如何检查 VS Code 侧边栏中打开的项目?