工作中要把bmp图片的数据转换成数组放到uboot代码中,因为有几张图片,使用bin转换成文本的工具还不如自己写脚本方便来得快 #!/usr/bin/env python import Image import sys im = Image.open(sys.argv[1]) width = im.size[0] height = im.size[1] print "/* width:%d */"%(width) print "/* height:%d */"%(height) count = 0 for h in range(0, height): for w in range(0, width): pixel = im.getpixel((w, h)) for i in range(0,3): count = (count+1)%16 if (count == 0): print "0x%02x,/n"%(pixel[i]), else: print "0x%02x,"%(pixel[i]),