如何逐像素绘制正方形(Python、PIL)

如何逐像素绘制正方形(Python、PIL),python,python-imaging-library,pixel,Python,Python Imaging Library,Pixel,在空白画布上,我想用枕头画一个正方形,逐像素 我试过使用img.putpixel30,60,155155,55来绘制一个像素,但它没有任何作用 from PIL import Image def newImg(): img = Image.new('RGB', (1280,768)) img.save('sqr.png') return img wallpaper = newImg() wallpaper.show() 运行你说你已经尝试过的代码完全有效,见下文

在空白画布上,我想用枕头画一个正方形,逐像素

我试过使用img.putpixel30,60,155155,55来绘制一个像素,但它没有任何作用

from PIL import Image

def newImg():
    img = Image.new('RGB', (1280,768))
    img.save('sqr.png')

    return img

wallpaper = newImg()

wallpaper.show()

运行你说你已经尝试过的代码完全有效,见下文

要绘制矩形,请使用其他坐标重复img.putpixel30,60,155155,55命令

from PIL import Image

def newImg():
    img = Image.new('RGB', (100, 100))
    img.putpixel((30,60), (155,155,55))
    img.save('sqr.png')

    return img

wallpaper = newImg()
wallpaper.show()
sqr.png


[

你看过PIL.ImageDraw了吗?不,我不能用它,它对我的任务来说太复杂了,它必须靠我自己一个像素一个像素地画一些东西。谢谢!我一定是在代码中把img.putpixel放错地方了。