Discuss / Python / 练习

练习

Topic source

冬凉默殇

#1 Created at ... [Delete] [Delete and Lock User]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import struct

def check_bmp(filename):
    with open(filename, 'rb') as f:
        header = f.read(30)
    s = struct.unpack('<ccIIIIIIHH', header)
    if s[0] == b'B' and s[1] in b'MA' and s[3] == 0 and s[8] == 1:
        print(s)
    else:
        print('error')


check_bmp('test.bmp')

  • 1

Reply