jpg转RGB565

#!/usr/bin/env python
import os,sys,Image

im=Image.open("/work1/1.jpg")
print "/* Image Width:%d Height:%d */" % (im.size[0], im.size[1])

print "unsigned short image[]={"
pix = im.load()  #load pixel array
for h in range(480):
	for w in range(800):
		if w < im.size[0]:
			R=pix[w,h][0]>>3
			G=pix[w,h][1]>>2
			B=pix[w,h][2]>>3
			rgb = (R<<11)|(G<<5)|B
			print "0x%x,"%(rgb)
		else:
			rgb =0
			print "0x0,"

print "};"

你可能感兴趣的:(jpg转RGB565)