What is the fastest way to draw an image from discrete pixel values in Python?

前端 未结 5 1854
时光取名叫无心
时光取名叫无心 2020-12-07 18:41

I wish to draw an image based on computed pixel values, as a means to visualize some data. Essentially, I wish to take a 2-dimensional matrix of color triplets and render it

5条回答
  •  北海茫月
    2020-12-07 19:34

    import Image
    im= Image.new('RGB', (1024, 1024))
    im.putdata([(255,0,0), (0,255,0), (0,0,255)])
    im.save('test.png')
    

    Puts a red, green and blue pixel in the top-left of the image.

    im.fromstring() is faster still if you prefer to deal with byte values.

提交回复
热议问题