Python 枕头:putpixel() 没有正确记录颜色

Python Pillow: putpixel() does not record the color correctly

我开始为我的游戏编写一个小型库。该库的本质是从镜像中读取配置。而我运行就陷入了这样的问题,记录颜色的时候没有正确记录!这是代码:

from PIL import Image

class CustomConfigReader:
    def __init__(self, path):
        self.configPath = path
        self.laters = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m", " ", ".", ",", "!", "?"]
    def edit(self, y, value):
        l1 = len(value)
        configImage = Image.open(self.configPath).convert("RGB")
        for i in range(0, l1):
            l2 = value[i]
            l3 = self.laters.index(l2)
            configImage.putpixel((i, y), (l3, l1, l1))
        configImage.save(self.configPath)
    def read(self, y):
        configImage = Image.open(self.configPath).convert("RGB")
        l1 = configImage.getpixel((0, y))[1]
        value = ""
        for i in range(0, l1-1):
            l3 = configImage.getpixel((i, y))[0]
            value += self.laters[l3]
        return value

事实证明问题出在 JPEG 格式上,我尝试将其更改为 png 并且一切正常!谢谢Mark Setchell