【发布时间】:2021-07-07 22:41:33
【问题描述】:
我正在尝试编写一个可以生成棋盘图案的代码。最终图像大小应为100 x 100,棋盘大小为5 x 5,这样每个框的尺寸为h/5 和w/5。我的代码是错误的:
from PIL import Image, ImageDraw
h = 500
w = 500
img = Image.new("RGB", (h,w), (255, 0, 0)) # create a new 15x15 image
pixels = img.load() # create the pixel map
print("1")
for i in range (h):
for j in range(w):
if ((i + j)%2) != 0:
im = Image.new('RGB', (h//5, w//5), 'black')
else:
draw = ImageDraw.Draw(img, "RGBA")
draw.rectangle(((h//5, w//5), (i+.5, j+.5)), fill="blue")
print ("done")
img.show()
【问题讨论】:
标签: python python-3.x image-processing python-imaging-library