用image模組更直接,可以用getpixel獲得畫素值,給你個例子吧。
01.#!/usr/bin/env python
02.import Image
03.import sys
04.im = Image.open(sys.argv[1])
05.width = im.size[0]
06.height = im.size[1]
07.print "/* width:%d */"%(width)
08.print "/* height:%d */"%(height)
09.count = 0
10.for h in range(0, height):
11. for w in range(0, width):
12. pixel = im.getpixel((w, h))
13. for i in range(0,3):
14. count = (count+1)%16
15. if (count == 0):
16. print "0x%02x,/n"%(pixel[i]),
17. else:
18. print "0x%02x,"%(pixel[i]),
用image模組更直接,可以用getpixel獲得畫素值,給你個例子吧。
01.#!/usr/bin/env python
02.import Image
03.import sys
04.im = Image.open(sys.argv[1])
05.width = im.size[0]
06.height = im.size[1]
07.print "/* width:%d */"%(width)
08.print "/* height:%d */"%(height)
09.count = 0
10.for h in range(0, height):
11. for w in range(0, width):
12. pixel = im.getpixel((w, h))
13. for i in range(0,3):
14. count = (count+1)%16
15. if (count == 0):
16. print "0x%02x,/n"%(pixel[i]),
17. else:
18. print "0x%02x,"%(pixel[i]),