def bmp_info(data): info = struct.unpack('<ccIIIIIIHH', data[:30]) if info[0] == b'B' and info[1] == b'M': return {'width':info[6], 'height':info[7],'color':info[9]} else : print('This is not a bitmap!')
bi = bmp_info(bmp_data) assert bi['width'] == 28 assert bi['height'] == 10 assert bi['color'] == 16 print('ok')
ok
Sign in to make a reply
Gin阿金
def bmp_info(data): info = struct.unpack('<ccIIIIIIHH', data[:30]) if info[0] == b'B' and info[1] == b'M': return {'width':info[6], 'height':info[7],'color':info[9]} else : print('This is not a bitmap!')
测试
bi = bmp_info(bmp_data) assert bi['width'] == 28 assert bi['height'] == 10 assert bi['color'] == 16 print('ok')