from PIL import Image
import re
img=Image.open('oxygen.png')
print(img.format,img.size,img.mode)
for x in range(img.size[0]):
for y in range(img.size[1]):
print(img.getpixel((x,y)))#观察特点
'''#一种方法
img_data=img.convert('L').getdata()
list1=[]
print(img.size)
for i in range(0,img.size[0],7):
list1.append(chr(img_data[img.size[0]*50+i]))
result=''.join(list1)
print(result)
list2=re.findall('(\d+)',result)
print(list2)
list3=[]
for each in list2:
list3.append(chr(int(each)))
result1=''.join(list3)
print(result1)
'''
y= 0
while True:
p = img.getpixel((0,y))
if p[0] == p[1] == p[2]:
break
y+= 1
x = 0
while True:
p = img.getpixel((x,y))
if not p[0] == p[1] == p[2]:
break
x+= 1
print(y,x)
result = []
for i in range(0,x,7):
p = img.getpixel((i,y))
result.append(chr(p[0]))
print(''.join(result))
result = re.findall('(\d+)',''.join(result))
print(''.join([chr(int(x)) for x in result]))
08-16
08-16
08-16