为什么 python 程序没有创建任何像素?

Why the python program is not creating any pixel?

import pyautogui as pug
from PIL import Image, ImageGrab
from time import sleep
from numpy import asarray

def screenshot():
    """Takes Screenshot of the current window"""
    img = ImageGrab.grab().convert('L')  #To convert the current image in B & W format 
    
    return img


if __name__ == "__main__":
    sleep(3)
    img = screenshot()
    data = img.load()
    print(asarray(img))  #Displays the image in matrix form
    #To make a black pixel over the image at coordinate(X:460 Y:320) [Not working :/]
    data[420,320] = 0
    img.show()

此代码应在图像上创建一个黑色像素:坐标 420、320 处的“img” 但问题是它不会创建这样的像素。我做错了什么?

谢谢

它确实有效! 1 像素太小,看不清。您可以增加要变黑的区域。

试试这个

for _ in range(410, 430):
    for __ in range(310, 330):
        data[_, __] = 0

而不是

data[420, 320] = 0