How to read the RGB value of a given pixel in Pyth

2019-01-02 14:40发布

If I open an image with open("image.jpg"), how can I get the RGB values of a pixel assuming I have the coordinates of the pixel?

Then, how can I do the reverse of this? Starting with a blank graphic, 'write' a pixel with a certain RGB value?

I would prefer if I didn't have to download any additional libraries.

13条回答
旧人旧事旧时光
2楼-- · 2019-01-02 15:46

As Dave Webb said:

Here is my working code snippet printing the pixel colours from an image:

import os, sys
import Image

im = Image.open("image.jpg")
x = 3
y = 4

pix = im.load()
print pix[x,y]
查看更多
登录 后发表回答