我正在从这里寻找示例和问题。我创造了东西。我希望 rgb 在像素上进行十六进制。我的代码,但我没有解决,
#-*- coding: utf-8 -*-
import Image
def read(ch):
return list(ch.getdata())
def hex2rgb(v):
v = v.lstrip('#')
lv = len(v)
return tuple(int(v[i:i+lv/3], 16) for i in range(0, lv, lv/3))
def rgb2hex(rgb):
return '#%02x%02x%02x' % rgb
imj = Image.open('sample.png','r')
x,y = imj.size
pix = list(imj.getdata())
if imj.mode in ('RGBA','LA') or (imj.mode == 'P' and 'transparency' in imj.info):
red,green,blue,alfa = imj.convert('RGBA').split()
#rgb = imj.convert('RGBA').split()[:-1]
r,g,b,a = read(red),read(green),read(blue),read(alfa)
for r_,g_,b_ in r,g,b:
print rgb2hex((r_,g_,b_))
r,g,b 中的 r_,g_,b_ 出现错误:但我如何解决不知道?
谢谢你的兴趣?干得好..