python图像库_我如何可以使用Python图像库创建位图

1586010002-jmsa.png

I have a 2d list in python, and I want to make a graphical pic of the data. Maybe a n by m column grid where each square is a different color of grey depending on the value in my 2d list.

However, I can't seem to figure out how to create images using PIL. This is some of the stuff I've been messing with:

def createImage():

img = Image.new('L', (100,100), 'white')

img.save('test.bmp')

for i in range(0,15):

for j in range(0,15):

img.putpixel((i,j), (255,255,255))

However, I'm getting an error saying that an integer is required (problem on the line with the putpixel)

解决方案import Image

img = Image.new( 'RGB', (255,255), "black") # create a new black image

pixels = img.load() # create the pixel map

for i in range(img.size[0]): # for every pixel:

for j in range(img.size[1]):

pixels[i,j] = (i, j, 100) # set the colour accordingly

img.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值