import struct def bmpinfo(s): try: s = struct.unpack('<ccIIIIIIHH', s) if s[0]==b'B' and s[1]==b'M': print('该图像为Windows位图\n图像大小:%s * %s\n颜色数:%s' % (s[6], s[7], s[9])) elif s[0]==b'B' and s[1]==b'A': print('该图像为OS/2位图\n图像大小:%s * %s\n颜色数:%s' % (s[6], s[7], s[9])) else: print('该文件并非位图文件(.bmp)') finally: print('finally...') s = open(filename, 'rb').read(30) bmpinfo(s)
Sign in to make a reply
Drak_C