首页 > 解决方案 > 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-3.xpython-imaging-librarytypeerrorsteganography

解决方案


推荐阅读